如何使用 Jenkins & 跨分支获得唯一的内部版本号管道多分支插件 [英] How can I have unique build numbers across branches with Jenkins & the Pipeline Multibranch Plugin

查看:20
本文介绍了如何使用 Jenkins & 跨分支获得唯一的内部版本号管道多分支插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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, as this allows traceability from an installed application through to the CI system, then to the change in source control, and then onto the issue that prompted the change.

The problem is that for each branch, the run number begins at 0. For a project with multiple branches, it seems impossible to guarantee a unique build number.

解决方案

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:

这篇关于如何使用 Jenkins & 跨分支获得唯一的内部版本号管道多分支插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆