Last active
June 14, 2016 07:05
-
-
Save tizki/0b3504b378912294adc886d3af519e98 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//posted at http://stackoverflow.com/a/37805003/947784 | |
import jenkins.model.Jenkins | |
import hudson.model.* | |
def jenkins = Jenkins.getInstance() | |
def jobName = "yourJobName" | |
String versionType = "minor" | |
def job = jenkins.getItem(jobName) | |
//get the current version parameter and update its default value | |
paramsDef = job.getProperty(ParametersDefinitionProperty.class) | |
if (paramsDef) { | |
paramsDef.parameterDefinitions.each{ | |
if("version".equals(it.name)){ | |
println "Current version is ${it.defaultValue}" | |
it.defaultValue = getUpdatedVersion(versionType, it.defaultValue) | |
println "Next version is ${it.defaultValue}" | |
} | |
} | |
} | |
//determine the next version by the required type | |
//and incrementing the current version | |
def getUpdatedVersion(String versionType, String currentVersion){ | |
def split = currentVersion.split('\\.') | |
switch (versionType){ | |
case "minor.minor": | |
split[2]=++Integer.parseInt(split[2]) | |
break | |
case "minor": | |
split[1]=++Integer.parseInt(split[1]) | |
break; | |
case "major": | |
split[0]=++Integer.parseInt(split[0]) | |
break; | |
} | |
return split.join('.') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment