Last active
November 30, 2015 11:35
-
-
Save judoole/2c5ae372332a0066d01b to your computer and use it in GitHub Desktop.
Update minor version of a Pipeline
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
//http://javadoc.jenkins-ci.org/ | |
/* | |
* Script for upping the minor version of the starting job, named ARTIFACT_PROJECT | |
* We expect every version to arrive here following this version strategy: major.minor | |
*/ | |
import hudson.model.* | |
import jenkins.model.Jenkins | |
//Get the parameters | |
def originalVersion = build.buildVariableResolver.resolve("VERSION") | |
def artifactProject = build.buildVariableResolver.resolve("ARTIFACT_PROJECT") | |
//Get the job we are upping | |
def job = Jenkins.getInstance().getItemByFullName(artifactProject) | |
assert job != null, "Could not find job with name $artifactProject" | |
assert originalVersion, "Missing parameter VERSION" | |
//Iterate and find actions of type Parameters | |
job.actions.grep{ it instanceof ParametersDefinitionProperty}.each{ | |
//Assume there is one named VERSION | |
def paramVersion = it.getParameterDefinition('VERSION').defaultValue | |
//If it is unchanged from the VERSION given to us, go ahead and up it | |
if(paramVersion == originalVersion){ | |
def majorMinorVersion = originalVersion.tokenize('.') | |
it.getParameterDefinition('VERSION').setDefaultValue("${majorMinorVersion[0]}.${majorMinorVersion[1].toInteger()+1}") | |
} | |
} | |
//Ensure that it also works after a restart | |
job.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment