Created
June 14, 2016 05:39
-
-
Save oillio/14cb6621877ecfb3a1d711e0f31ace90 to your computer and use it in GitHub Desktop.
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
public class TriggerStep extends AbstractStepImpl { | |
private final String spec; | |
@DataBoundConstructor | |
public TriggerStep(String spec) { | |
this.spec = spec; | |
} | |
public String getSpec() { | |
return spec; | |
} | |
public static class Execution extends AbstractSynchronousStepExecution<Void> { | |
private static final long serialVersionUID = 1L; | |
@Inject | |
transient TriggerStep step; | |
@StepContextParameter | |
transient Run<?,?> build; | |
@Override | |
protected Void run() throws Exception { | |
Job<?,?> parent = build.getParent(); | |
if(parent instanceof WorkflowJob) { | |
WorkflowJob job = (WorkflowJob) parent; | |
job.addTrigger(new SCMTrigger(step.getSpec())); | |
job.save(); | |
} else { | |
throw new AbortException("cannot apply trigger to job of type " + parent.getClass().getSimpleName()); | |
} | |
return null; | |
} | |
} | |
@Extension | |
public static class DiscriptorImpl extends AbstractStepDescriptorImpl { | |
public DiscriptorImpl() { | |
super(Execution.class); | |
} | |
@Override | |
public String getFunctionName() { | |
return "scmTrigger"; | |
} | |
@Override | |
public String getDisplayName() { | |
return "Set an SCM Trigger for this project."; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment