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

后端 未结 3 552
悲&欢浪女
悲&欢浪女 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:48

    One way is to have a Job that is being called from all branches and using it's build number. That job can be just a normal pipeline job with a dummy Jenkinsfile like echo "hello". Then just call it like this

    def job = build job: 'build number generator', quietPeriod: 0, parameters: [
            string(value: "${BRANCH_NAME}-${BUILD_NUMBER}", name: 'UID')  
    ]
    def BNUMBER = job.getNumber().toString()
    currentBuild.displayName = "build #"+BNUMBER
    echo BNUMBER
    

    Not sure if that UID parameter is needed but it forces all calls into "build number generator" job to be unique so Jenkins wouldn't optimize builds that happen at same time to use same "build number generator" job.

提交回复
热议问题