Jenkinsfile get current tag

后端 未结 8 1916
南笙
南笙 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:35

    best way from my site is:

    git tag --sort=-creatordate | head -n 1
    

    with:

    latestTag = sh(returnStdout:  true, script: "git tag --sort=-creatordate | head -n 1").trim()
    

    Than you can handle with simple regex, for prefix/suffix/version_number what is to do with the tag.

    other solution:

    git describe --tags --abbrev=0
    

    of course this is the current/latest tag in git. Independent from writing.

    sh(returnStdout: true, script: "git describe --tags --abbrev=0").trim()
    

提交回复
热议问题