Created
January 18, 2018 16:55
-
-
Save gokart23/a2aedaf8617e765f7b22e6cee976f9ae to your computer and use it in GitHub Desktop.
Programmatically trigger a pipeline run (with custom data) in Jenkins
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
import jenkins.model.*; | |
import hudson.model.Job; | |
import hudson.model.Run; | |
import hudson.model.queue.QueueTaskFuture; | |
import org.jenkinsci.plugins.workflow.cps.replay.ReplayAction; | |
String text = "node('some-node') { echo 'hi'; }" | |
Job test_job = Jenkins.getInstance().getItemByFullName("pipeline-job-name", hudson.model.Job); | |
ReplayAction action = test_job.getLastBuild().getAction(ReplayAction.class) | |
QueueTaskFuture<? extends Run> f = action.run(text, action.getOriginalLoadedScripts()) | |
Run b = f.waitForStart() | |
println "Started job" | |
while (b.isBuilding()) { | |
Thread.sleep(1000); | |
} | |
println "Job completed" | |
b.delete() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment