notatio/Jenkinsfile

71 lines
2.2 KiB
Text
Raw Normal View History

2023-11-20 22:10:40 -06:00
pipeline {
agent {
label 'podman'
}
tools {
go '1.21.1'
}
environment {
registry = "docker.io/notatio/notatio"
registryCredential = 'docker-hub-credentials'
podmanImage = ''
}
stages {
stage('Clone repository') {
steps {
git branch: 'main', credentialsId: 'codeberg-musselman-builder-jenkins', url: 'https://codeberg.org/Musselman/Notatio.git'
}
}
stage('Retrieve Git tag') {
steps {
script {
def tagOutput = sh(script: 'git describe --abbrev=0 --tags || true', returnStdout: true).trim()
if (tagOutput.isEmpty() || tagOutput.equals("fatal: No names found, cannot describe anything.")) {
TAG = 'latest' // Set a default tag if no tags are found
echo "No tags found, using default tag: ${TAG}"
} else {
TAG = tagOutput
echo "Latest tag found: ${TAG}"
}
}
}
}
stage('Build') {
steps {
echo 'Building..'
sh 'go build'
}
}
stage('Test') {
steps {
echo 'Testing..'
echo 'No Testing to do currently..'
}
}
stage('Building image') {
steps {
script {
sh "podman build -t notatio ."
}
}
}
stage('Push image') {
steps {
script {
withCredentials([usernamePassword(credentialsId: registryCredential, passwordVariable: 'REGISTRY_PASSWORD', usernameVariable: 'REGISTRY_USERNAME')]) {
sh "podman login -u $REGISTRY_USERNAME -p $REGISTRY_PASSWORD docker.io"
sh "podman push notatio $registry:${TAG}"
sh "podman logout $registry"
}
}
}
}
stage('Cleanup') {
steps {
sh "podman rmi -a -f"
}
}
}
}