ligi ligi - 3 months ago 136
Git Question

Jenkinsfile get current tag

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 this commit has a tag.
I tried:

env.TAG_NAME


and

binding.variables.get("TAG_NAME")


both are always null - even though this ( https://issues.jenkins-ci.org/browse/JENKINS-34520 ) indicates otherwise

Answer
sh "git tag --sort version:refname | tail -1 > version.tmp"
String tag = readFile 'version.tmp'