如何自动增加jenkins的内部版本号? [英] How to increase jenkins build number automatically?

查看:505
本文介绍了如何自动增加jenkins的内部版本号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何自动增加jenkins的内部版本号或使用shell脚本? 现在,我正在使用configure选项进行相同的操作,并手动进行增加.我想自动做.

How to increase jenkins build number automatically or by using shell script?? For now i am doing the same using configure option, and increasing manually. i want to do it automatically.

推荐答案

您要的内容(即,在多个作业之间保持内部版本号相同)只是在詹金斯(Jenkins)中不可能.这是通过设计(如詹金斯创建者本人所指出的)完成的: .您可以将其更改为更高的值,但是将其更改为相同的数字将彻底破坏詹金斯的身分,因此是不可能的.

What you are asking for (i.e. keeping the build number same between multiple jobs) is simply impossible in Jenkins. This is done by design (as noted by Jenkins creator himself): "[JENKINS] assumes that the build number is unique and monotonic.". You can change it to a higher value, but changing it to same number will outright break Jenkins and is therefore not possible.

建立 run 号就是:一个 run 号.
应该是连续的.
它不是不是版本号.

Build run number is just that: a run number.
It is supposed to be sequential.
It is not a version number in any way.

但是,有几种方法可以将版本信息添加到构建历史记录中.

There are several ways to get versioning information into the build history however.

Description Setter插件
这就是我用的.它不会更改内部版本号,但会更改说明,这是自动完成的.此外,由于这是描述,因此也可以随时手动对其进行修改.

Description Setter Plugin
This is what I use. It doesn't change the build number, but rather the description, which is done automatically. Furthermore, since this is a description, it can also be modified manually at any time.

这是它的样子:

请注意,版本#50#51实际上具有相同的版本1.3.0.394376.
在该版本字符串中,1.3.0是由项目属性确定的当前发行版号,而394376实际上是从$SVN_REVISION_1构建变量获得的SVN修订版号.因此,每当SVN中有一个新的提交时,我都会得到一个新的修订号.但是,如果没有提交并且由于某种原因(例如在#50#51中)重建了作业,则我的版本号将保持不变,因为没有 code 更改.

This is what it looks like:

Note that builds #50 and #51 actually have the same version 1.3.0.394376.
In that version string, the 1.3.0 is the current release number, as determined by the project properties, while the 394376 is actually an SVN revision number, obtained from $SVN_REVISION_1 build variable. So every time there is a new commit in SVN, I get a new revision number. But if there are no commits and the job is rebuilt for whatever reason (like in #50 and #51), my version number remains same, as there was no code change.

我配置它的方式是:

  • 下载描述设置工具插件
  • 在您的构建步骤中的某处,输出您的版本*
  • 我只是拥有:
    echo Version is: ${internalVersionNumberFromWherever}.${SVN_REVISION_1}
  • 接下来的设置构建后操作设置构建说明
  • 设置正则表达式以从控制台中提取版本号: Version is: (.*)
  • 将其他所有内容留空,(.*)中提取的RegEx将用作描述.
  • 或者,您可以进一步将说明文本设置为Build - \1.其中\1是RegEx对第一个组(.*)的引用.
  • 您随时可以手动更改运行的描述,方法是从构建历史记录中选择构建运行,然后单击右侧的编辑描述" 链接( (前提是该用户已配置更新" 权限).
  • Download Description Setter Plugin
  • Somewhere in your Build Steps, output your version *
  • I simply have:
    echo Version is: ${internalVersionNumberFromWherever}.${SVN_REVISION_1}
  • Next setup Post-build Action with Set build description
  • Setup Regular expression to extract the version number from the console: Version is: (.*)
  • Leave everything else blank, and the whatever RegEx picks up in (.*) will be used as description.
  • Alternatively, you can further set Description text as Build - \1. Where \1 is a reference to first group (.*) from the RegEx.
  • At any time you can manually change the description of the run by selecting the build run from the build history, and clicking "edit description" link on the right (provided that user has "Update" permissions configured).

*请注意,如果在输出版本文本的步骤之前构建失败,则说明设置插件将无法使用它.如果您始终想查看版本,那么第一步就是设置版本号显示.

构建名称设置器插件
该插件实际上会更改内部版本号

但是请记住,每个内部版本号必须唯一的限制.
确保这一点的最佳方法是将${BUILD_NUMBER}添加到所需的任意数字(如上图所示).这样,您可以拥有类似50.123然后是50.124的内部版本号,其中50是您的版本,而123124是顺序的内部版本 run ,詹金斯(Jenkins)确保保持${BUILD_NUMBER}唯一.

Build Name Setter plugin
This plugin will actually change the build number

However remember the limitation that each build number has to be unique.
Best way to ensure that is to add ${BUILD_NUMBER} to whatever arbitrary number that you want (like in the image above). This way you can have builds numbers like 50.123 and then 50.124 where 50 is your version while 123 and 124 are sequential build run numbers, and Jenkins makes sure of keeping the ${BUILD_NUMBER} unique.

最后,有一个 版本号插件 ,我没有亲自尝试过,但这可能会对您有所帮助.

Finally, there is the Version Number plugin which I haven't personally tried, but it may help you.

这篇关于如何自动增加jenkins的内部版本号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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