简体   繁体   English

如何使用jenkins版本号插件每天重置内部版本号1以在版本中使用

[英]How to use jenkins version number plugin to reset the build number everyday 1 to use in the version

How can i update the version build number everyday. 我如何每天更新版本内部版本号。 I have a version format "${BUILD_TIMESTAMP}.${BUILDS_ALL_TIME}", my build version are based on the date and the build number. 我的版本格式为“ $ {BUILD_TIMESTAMP}。$ {BUILDS_ALL_TIME}”,我的构建版本基于日期和内部版本号。

 So i want to reset (or make it start from 1) the Build number everyday as the date changes.

Ex: If today i have five builds then the version will "2019-09-10.5" and for tomorrow the if its the first build then i want the value to be "2019-09-11.1" but using the above values i'm getting the next build number in the next day build. 例如:如果今天我有五个版本,那么版本将为“ 2019-09-10.5”,明天为如果是第一个版本,则我希望该值为“ 2019-09-11.1”,但我使用上述值在第二天的版本中获取下一个版本号。 ie version="2019-09-11.6" 即版本=“ 2019-09-11.6”

So How can i reset or make it to 1 every next day for the first Build. 因此,我如何才能在第二天的第二天将其重置或设置为1。

Have tried using different options of the version build number but nothing worked as per my requirement 尝试使用版本内部版本号的不同选项,但没有按照我的要求工作

You need to create another pipeline job with below mentioned content: 您需要使用以下内容创建另一个管道作业:

node() { stage('Cleaning the Jenkins project history'){ def myJob = Jenkins.instance.getItem('job_name_to_reset') myJob.getBuilds().each { it.delete() } myJob.nextBuildNumber = 1 myJob.save() } } node() { stage('Cleaning the Jenkins project history'){ def myJob = Jenkins.instance.getItem('job_name_to_reset') myJob.getBuilds().each { it.delete() } myJob.nextBuildNumber = 1 myJob.save() }}

Schedule this job to run everyday at midnight and it will delete the build history and reset the count to 0. Note: You need to deselect Use Groovy Sandbox option otherwise it will ask for script approval each time. 将此作业安排为每天午夜运行,它将删除构建历史记录并将计数重置为0。注意:您需要取消选择Use Groovy Sandbox选项,否则每次都会要求脚本批准。

OR 要么

If you don't want to delete the build history, then you can go with this approach: Changing Jenkins build number 如果您不想删除构建历史记录,则可以采用以下方法: 更改Jenkins内部版本号

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM