Skip to content

Instantly share code, notes, and snippets.

@alces
Last active June 14, 2017 09:07
Show Gist options
  • Save alces/f4baa2e1435bd8cac7a80ab654de8dce to your computer and use it in GitHub Desktop.
Save alces/f4baa2e1435bd8cac7a80ab654de8dce to your computer and use it in GitHub Desktop.
Schedule a build of a Jenkins job and print its URL after its start.
import hudson.model.*
// in order to pass environment variables into build, EnvInjectPlugin should be installed
import org.jenkinsci.plugins.envinject.EnvInjectPluginAction
println Hudson.instance.getItem('down_stream_job_name').scheduleBuild2(
5, // quiet period
new ParametersAction( // build parameters
new StringParameterValue('STR_PARAM', 'Its value'), // string parameter
new BooleanParameterValue('BOOL_PARAM', true) // boolean parameter
),
new EnvInjectPluginAction( // environment variables
ENV_VAR01: "I'm from upstream",
ENV_VAR02: "And I'm from there too"
)
).waitForStart().absoluteUrl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment