Skip to content

Instantly share code, notes, and snippets.

@eshack94
Forked from aespinosa/job.groovy
Created April 7, 2019 18:30
Show Gist options
  • Save eshack94/aa5650e347190f638b104bddb4cbb1bc to your computer and use it in GitHub Desktop.
Save eshack94/aa5650e347190f638b104bddb4cbb1bc to your computer and use it in GitHub Desktop.
create a jenkins job in the script console
import jenkins.model.Jenkins;
import hudson.model.FreeStyleProject;
import hudson.tasks.Shell;
job = Jenkins.instance.createProject(FreeStyleProject, 'job-name')
job.buildersList.add(new Shell('echo hello world'))
job.save()
build = job.scheduleBuild2(5, new hudson.model.Cause.UserIdCause())
build.get() # Block until the build finishes
generatedJobs = build.getAction(javaposse.jobdsl.plugin.actions.GeneratedJobsBuildAction).getItems()
# FIXME skip .scheduleBuild2() on Folder jobs
generatedJobs.each { j -> j.scheduleBuild2(5, new hudson.model.Cause.UserIdCause()) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment