Jenkinsfile get current tag

后端 未结 8 1874
南笙
南笙 2021-02-05 10:15

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

相关标签:
8条回答
  • 2021-02-05 10:53

    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

    0 讨论(0)
  • 2021-02-05 10:56

    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")

    0 讨论(0)
提交回复
热议问题