Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set build number for Jenkins workflow (pipeline) builds

I am migrating jenkins-workflow job to new template based workflow job. Because the build number is used as part of the version of build artifacts the workflow produces I have to start build number of the new workflow with a number greater than the old workflow. Unfortunately 'Next Build Number' plugin does not work with workflow pipeline.

Anybody knows a good way do this?

like image 312
Vlad Avatar asked Jan 22 '16 16:01

Vlad


People also ask

How do you limit the number of builds stored in the build history in Jenkins?

This is a feature that is given to you by Jenkins so you can change the number of builds you want to keep. If you are using a Declarative pipeline you can just add this to your code: pipeline { options { buildDiscarder(logRotator(numToKeepStr: '30', artifactNumToKeepStr: '30')) } ... }

How do I find the build number in Jenkins pipeline?

BUILD_NUMBER is the current build number. You can use it in the command you execute for the job, or just use it in the script your job executes.


1 Answers

Or, you could add a snippet like this to your Pipeline/Workflow job DSL script (aka Jenkinsfile):

offset = 5
currentBuild.displayName = "#" + (currentBuild.number + offset)
like image 113
MarkHu Avatar answered Oct 19 '22 16:10

MarkHu