Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Brantone/cc357a36d6199112a3fa9d80f8588802 to your computer and use it in GitHub Desktop.
Save Brantone/cc357a36d6199112a3fa9d80f8588802 to your computer and use it in GitHub Desktop.
invoke a downstream jenkins job with the current job parameters + additions
import hudson.model.*
// extract the version tag from the console log
def version_pattern = ".*\\[\\s*INFO\\s*\\]\\s+VERSION=(.*)\\s*\$"
def matcher = manager.getLogMatcher( version_pattern )
if ( matcher?.matches() ) {
// add the version string to the job summary
def ver = matcher.group(1)
manager.addInfoBadge( "Version: $ver" )
manager.createSummary("gear2.gif").appendText("<b>Version:</b> $ver", false )
// prepare a list of parameters from the current build
def params = []
for ( p in manager.build.getActions().find{ it instanceof ParametersAction } ) {
params.push( new StringParameterValue( p.name, p.value ) )
}
// add the version string
params.push( new StringParameterValue( 'VERSION_STRING', ver ) )
// schedule a build of the downstream job with current parameters
def job = manager.hudson.getJob('test-verification-Hello-Discworld-linux-x86-release')
job.scheduleBuild( 2, new Cause.UpstreamCause( manager.build ), new ParametersAction( params ) )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment