Skip to content

Instantly share code, notes, and snippets.

@robmaidment
Created February 7, 2017 15:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save robmaidment/64c5bcdf8808f0c42947a4a78ed1ee2c to your computer and use it in GitHub Desktop.
Save robmaidment/64c5bcdf8808f0c42947a4a78ed1ee2c to your computer and use it in GitHub Desktop.
Using a Jenkins system groovy script to trigger another job, based on an input parameter
import jenkins.*
import jenkins.model.*
import hudson.*
import hudson.model.*
def SELECTED_JOB = build.buildVariableResolver.resolve("SELECTED_JOB")
def target = Jenkins.instance
.getItemByFullName(SELECTED_JOB) ?: null
if (!target) {
println "No downstream job found"
} else {
println "I found it!"
def execution = target.scheduleBuild2(0, new Cause.UpstreamCause(build))
println "Running test job:"
println "Complete, result was: " + execution.get().result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment