Is there a way to get the current tag ( or null if there is none ) for a job in a Jenkinsfile? The background is that I only want to build some artifacts ( android APKs ) when t
The TAG_NAME
should work now at least in declarative pipelines.
When
condition actually filters on this property. BRANCH_NAME
has the same value.
stage('release') {
when {
tag 'release-*'
}
steps {
echo "Building $BRANCH_NAME"
echo "Building $TAG_NAME"
}
}
See https://jenkins.io/doc/book/pipeline/syntax/#when
I believe the git command that does what you want is git tag --points-at=HEAD
this will list all tags pointing to the current commit or HEAD as it usually called in git. Since HEAD is also the default argument you can also do just git tag --points-at
.
The pipeline step for executing and returning the git tags one for each line, then becomes:
sh(returnStdout: true, script: "git tag --points-at")