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

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

问题描述

我们正在将Jenkins Pipeline Multibranch插件与Blue Ocean结合使用.

We are using Jenkins Pipeline Multibranch Plugin with Blue Ocean.

通过我的阅读,我相信将项目的内部版本号与Jenkins运行联系在一起是很常见的,因为这允许从已安装的应用程序到CI系统,再到源代码管理的更改,再到源代码的更改的可追溯性.促使更改的问题.

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.

问题在于,对于每个分支,运行号都从0开始.对于具有多个分支的项目,似乎无法保证唯一的内部版本号.

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?

根据管道语法:全局变量参考",currentBuild.displayName是可写属性.所以你可以将附加信息添加到内部版本号(以便使其在全局范围内唯一),并在后续工件/应用程序构建步骤中使用该字符串(以将其合并到应用程序的版本输出中以实现所需的可追溯性),例如像这样:

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

使用格式化的时间表或开始时间(currentBuild.timeInMillis)作为可读日期,或使用SCM修订版也可能很有用,例如结果为"20180119-091439-rev149923".

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

另请参阅:

  • 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

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

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