1

How can I modify the BUILD_DISPLAY_NAME so that is the build number but zero padded?

For example, if Jenkins build number is 54, I would like the name to be 00054.

Veehmot
  • 161
  • 2
  • 10
  • Is this a Jenkins question, or was Jenkins just an example? – Dan Dec 02 '13 at 15:21
  • No, it is related to Jenkins. I'm comfortable zero padding numbers in programming but I'm expecting how to do the same thing using Jenkins plugins. – Veehmot Dec 02 '13 at 15:27

3 Answers3

1

Use the Build Name Setter Plugin. During your build you just need to write the build number in the right format to a property file and it will be picked up when the build finishes.

Peter Schuetze
  • 1,241
  • 10
  • 17
  • So that includes manually modifying a file every time a build is done? – Veehmot Dec 03 '13 at 13:34
  • I wouldn't call it manual to have a buildstep that generates the file during your build. Alternative would be to create a plugin that either sets the build number for you or having a plugin that does the formatting for you by having a plugin that extends the token macro plugin. – Peter Schuetze Dec 03 '13 at 14:04
1

The Build Name setter is an option, as already reported by Peter Schuetze. Personally, I have found it a bit cumbersome, so I also use a Groovy System script (from the Groovy plugin) with the following snippet (e.g. set the build name from the Build paramters, which is not related to the actual question, I know):

def resolver = build.buildVariableResolver
build.setDisplayName(build.displayName+"_"+resolver.resolve("BUILD_TYPE"))
Patrice M.
  • 213
  • 1
  • 7
1

Following advice from @patrice-m, I used the Scriptler plugin, and created the following script:

return String.format("%04d", Thread.currentThread().executable.getNumber());

Also, I make sure to activate both Permission and Restriction checkboxes, which will allow the script to be run by everybody, and on a Master thread (necessary to access the current build).

Veehmot
  • 161
  • 2
  • 10