I want to use git tags within my declarative Jenkins pipeline. My Jenkinsfile looks like this
pipeline {
agent any
stages {
stage('Setup') {
steps {
script {
env.MY_GIT_TAG = sh(returnStdout: true, script: 'git tag -l --points-at HEAD')
// ...
}
}
}
stage('Build'){
// build my code etc ....
}
stage('Publish') {
// push code somewhere depending on tag
sh "curl -X POST --upload-file ./MyDeployable https://someserver/uri/MyDeployable-${env.MY_GIT_TAG}"
}
}
}
But the environment variable MY_GIT_TAG
was always empty. After some investigation i noticed this in my Jenkins logs:
git fetch --no-tags --progress ...
Is there a way to tell Jenkins to skip the --no-tags
argument?
As i do not know beforehand how the commit is tagged i want to checkout the tag from git and use it as a variable. So the solution in this question is not viable here.