Search in sources :

Example 1 with CpsThread

use of org.jenkinsci.plugins.workflow.cps.CpsThread in project workflow-cps-plugin by jenkinsci.

the class ArgumentsActionImplTest method simpleSemaphoreStep.

@Test
public void simpleSemaphoreStep() throws Exception {
    WorkflowJob job = r.jenkins.createProject(WorkflowJob.class, "p");
    job.setDefinition(new CpsFlowDefinition("semaphore 'wait'"));
    WorkflowRun run = job.scheduleBuild2(0).getStartCondition().get();
    SemaphoreStep.waitForStart("wait/1", run);
    FlowNode semaphoreNode = run.getExecution().getCurrentHeads().get(0);
    CpsThread thread = CpsThread.current();
    SemaphoreStep.success("wait/1", null);
    r.waitForCompletion(run);
    testDeserialize(run.getExecution());
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) CpsThread(org.jenkinsci.plugins.workflow.cps.CpsThread) Test(org.junit.Test)

Example 2 with CpsThread

use of org.jenkinsci.plugins.workflow.cps.CpsThread in project workflow-cps-plugin by jenkinsci.

the class ParallelStepExecution method start.

@Override
public boolean start() throws Exception {
    CpsStepContext cps = (CpsStepContext) getContext();
    if (parallelStep.closures.isEmpty()) {
        cps.get(TaskListener.class).getLogger().println("No branches to run");
        cps.onSuccess(Collections.<String, Object>emptyMap());
        return true;
    }
    CpsThread t = CpsThread.current();
    ResultHandler r = new ResultHandler(cps, this, parallelStep.isFailFast());
    for (Entry<String, Closure> e : parallelStep.closures.entrySet()) {
        BodyExecution body = cps.newBodyInvoker(t.getGroup().export(e.getValue())).withStartAction(new ParallelLabelAction(e.getKey())).withCallback(r.callbackFor(e.getKey())).start();
        bodies.add(body);
    }
    return false;
}
Also used : CpsStepContext(org.jenkinsci.plugins.workflow.cps.CpsStepContext) BodyExecution(org.jenkinsci.plugins.workflow.steps.BodyExecution) Closure(groovy.lang.Closure) ResultHandler(org.jenkinsci.plugins.workflow.cps.steps.ParallelStep.ResultHandler) CpsThread(org.jenkinsci.plugins.workflow.cps.CpsThread)

Example 3 with CpsThread

use of org.jenkinsci.plugins.workflow.cps.CpsThread in project workflow-cps-plugin by jenkinsci.

the class LoadStepExecution method start.

@Override
public boolean start() throws Exception {
    CpsStepContext cps = (CpsStepContext) getContext();
    CpsThread t = CpsThread.current();
    CpsFlowExecution execution = t.getExecution();
    String text = cwd.child(step.getPath()).readToString();
    String clazz = execution.getNextScriptName(step.getPath());
    String newText = ReplayAction.replace(execution, clazz);
    if (newText != null) {
        listener.getLogger().println("Replacing Groovy text with edited version");
        text = newText;
    }
    Script script = execution.getShell().parse(text);
    // execute body as another thread that shares the same head as this thread
    // as the body can pause.
    cps.newBodyInvoker(t.getGroup().export(script)).withDisplayName(step.getPath()).withCallback(BodyExecutionCallback.wrap(cps)).start();
    return false;
}
Also used : CpsStepContext(org.jenkinsci.plugins.workflow.cps.CpsStepContext) Script(groovy.lang.Script) CpsFlowExecution(org.jenkinsci.plugins.workflow.cps.CpsFlowExecution) CpsThread(org.jenkinsci.plugins.workflow.cps.CpsThread)

Aggregations

CpsThread (org.jenkinsci.plugins.workflow.cps.CpsThread)3 CpsStepContext (org.jenkinsci.plugins.workflow.cps.CpsStepContext)2 Closure (groovy.lang.Closure)1 Script (groovy.lang.Script)1 CpsFlowDefinition (org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition)1 CpsFlowExecution (org.jenkinsci.plugins.workflow.cps.CpsFlowExecution)1 ResultHandler (org.jenkinsci.plugins.workflow.cps.steps.ParallelStep.ResultHandler)1 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)1 WorkflowJob (org.jenkinsci.plugins.workflow.job.WorkflowJob)1 WorkflowRun (org.jenkinsci.plugins.workflow.job.WorkflowRun)1 BodyExecution (org.jenkinsci.plugins.workflow.steps.BodyExecution)1 Test (org.junit.Test)1