Reputation: 795
I'm trying to use the BUILD_NUMBER
environment property to create a tag that I can pass down to my ANT script (so that I can write it to my WAR/JAR manifest) as well as use it during the tagging process executed by the "Subversion Tagging Plugin".
A minor complication is that I'd like to zero-pad the BUILD_NUMBER
before using it. For example, if the BUILD_NUMBER
is 14, my tag would look like 1.0.0.00014.
I've found the EnvInject plugin which has an "Evaluated Groovy script" feature and this script works for me, but I do have questions:
import jenkins.model.*
def tagPrefix = "1.0.0."
def env = Jenkins.instance.getItem("BnL Build").getLastBuild().getEnvironment()
def buildNumber = env['BUILD_NUMBER']
def tag = tagPrefix + buildNumber.padLeft(5,'0')
def map = [AP_SVN_TAG: tag]
return map
Questions are:
Jenkins.instance.getItem()
? I know that works, but seems fragile given that the Job's name could change at any time and thus break the script. I tried manager.build.getEnvironment(manager.listener)['BUILD_NUMBER']
instead, but I got an error that [EnvInject] - [ERROR] - SEVERE ERROR occurs: No such property: manager for class: Script1
.If it helps I'm running Jenkins v1.488, Jenkins Subversion Tagging Pluging v1.16 and Environment Injector Pluging v1.73.
Thanks in advance,
Matt
Upvotes: 1
Views: 865
Reputation: 795
The plugin has now been updated to version 1.75 by gboissinot and makes the variables currentJob
and currentBuild
available to the Groovy script. So my new Groovy script is:
import jenkins.model.*
def tagPrefix = "1.0.0."
def buildNumber = currentBuild.getNumber().toString()
def tag = tagPrefix + buildNumber.padLeft(5,'0')
def map = [AP_SVN_TAG: tag]
return map
And it works great!
Upvotes: 1