Matt Felzani
Matt Felzani

Reputation: 795

Jenkins: Create and Pass SVN Tag to ANT and Subversion Tagging Plugin

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:

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

Answers (1)

Matt Felzani
Matt Felzani

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

Related Questions