Search code examples
gitjenkinsjenkins-2

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


Solution

  • I'd consider returnStdout rather than writing to a file:

    sh(returnStdout: true, script: "git tag --sort version:refname | tail -1").trim()