How can I have unique build numbers across branches with Jenkins & the Pipeline Multibranch Plugin

后端 未结 3 541
悲&欢浪女
悲&欢浪女 2021-02-13 23:34

We are using Jenkins Pipeline Multibranch Plugin with Blue Ocean.

Through my reading, I believe it is quite common to tie your project\'s build number to the Jenkins run

3条回答
  •  臣服心动
    2021-02-13 23:40

    Maybe instead of a unique (global numeric) build number you might want to try a unique (global) build display name?

    According to "pipeline syntax: global variables reference" currentBuild.displayName is a writable property. So you could e.g. add additional information to the build number (in order to make it globally unique) and use that string in subsequent artifact/application build steps (to incorporate that in the application's version output for your desired traceability), e.g. something like:

    currentBuild.displayName = "${env.BRANCH_NAME}-${currentBuild.id}"
    

    Using the build's schedule or start time formatted (currentBuild.timeInMillis) as a readable date, or using the SCM revision might be also useful, e.g. resulting in "20180119-091439-rev149923".

    See also:

    • https://groups.google.com/forum/#!msg/jenkinsci-users/CDuWAYLz2zI/NLxwOku4AwAJ
    • https://support.cloudbees.com/hc/en-us/articles/220860347-How-to-set-build-name-in-Pipeline-job

提交回复
热议问题