Skip to content
Permalink
Browse files

Merge pull request #5 from jenkinsci/block-step-JENKINS-26107

[JENKINS-26107] stage may now take a block
  • Loading branch information...
svanoort committed Aug 30, 2016
2 parents 4711a80 + d7b9a5f commit d6a220b262424bdf0f6ffd515eac397390e94cd4
11 pom.xml
@@ -4,8 +4,8 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.5</version>
<relativePath />
<version>2.13</version>
<relativePath/>
</parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>pipeline-stage-step</artifactId>
@@ -49,7 +49,12 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>1.15</version>
<version>2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>2.1-SNAPSHOT</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
@@ -63,6 +63,10 @@ public DescriptorImpl() {
return "Stage";
}

@Override public boolean takesImplicitBlockArgument() {
return true;
}

}

}
@@ -34,6 +34,7 @@
import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.jenkinsci.plugins.workflow.graph.FlowStartNode;
import org.jenkinsci.plugins.workflow.steps.AbstractStepExecutionImpl;
import org.jenkinsci.plugins.workflow.steps.BodyExecutionCallback;
import org.jenkinsci.plugins.workflow.steps.FlowInterruptedException;
import org.jenkinsci.plugins.workflow.steps.StepContext;
import org.jenkinsci.plugins.workflow.steps.StepContextParameter;
@@ -46,7 +47,6 @@
@Inject(optional=true) private transient StageStep step;
@StepContextParameter private transient Run<?,?> run;
@StepContextParameter private transient FlowNode node;
@StepContextParameter private transient TaskListener listener; // picked up by getRequiredContext

private static final class StageActionImpl extends InvisibleAction implements StageAction {
private final String stageName;
@@ -60,6 +60,14 @@

@Override
public boolean start() throws Exception {
if (getContext().hasBody()) { // recommended mode
if (step.concurrency != null) {
throw new AbortException(Messages.StageStepExecution_concurrency_not_supported_in_block_mode());
}
getContext().newBodyInvoker().withCallback(BodyExecutionCallback.wrap(getContext())).withDisplayName(step.name).start();
return false;
}
getContext().get(TaskListener.class).getLogger().println(Messages.StageStepExecution_non_block_mode_deprecated());
if (isInsideParallel(node)) {
throw new AbortException(Messages.StageStepExecution_the_stage_step_must_not_be_used_inside_a());
}
@@ -28,7 +28,4 @@ THE SOFTWARE.
<f:entry field="name" title="Stage Name">
<f:textbox/>
</f:entry>
<f:entry field="concurrency" title="Concurrency">
<f:number clazz="positive-number"/>
</f:entry>
</j:jelly>

This file was deleted.

@@ -1,6 +1,5 @@
<div>
By default, Pipeline builds can run concurrently.
The stage command lets you mark certain sections of a build as being constrained by limited concurrency.
Newer builds are always given priority when entering such a throttled stage; older builds will simply exit early if
they are preempted.
Creates a labeled block.
<p>
An older, deprecated mode of this step did not take a block argument, and accepted a <code>concurrency</code> parameter.
</div>
@@ -1 +1,3 @@
StageStepExecution.the_stage_step_must_not_be_used_inside_a=The \u2018stage\u2019 step must not be used inside a \u2018parallel\u2019 block.
StageStepExecution.concurrency_not_supported_in_block_mode=The \u2018concurrency\u2019 parameter is not supported in block-mode \u2018stage\u2019; try \u2018lock\u2019 and/or \u2018milestone\u2019 steps instead
StageStepExecution.non_block_mode_deprecated=Using the \u2018stage\u2019 step without a block argument is deprecated

This file was deleted.

@@ -53,6 +53,20 @@
StageStepExecution.clear();
}

@Issue("JENKINS-26107")
@Test public void blockMode() throws Exception {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("stage('hello there') {echo 'yes I ran'}", true));
WorkflowRun b = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0));
story.j.assertLogContains("hello there", b);
story.j.assertLogContains("yes I ran", b);
story.j.assertLogNotContains(Messages.StageStepExecution_non_block_mode_deprecated(), b);
}
});
}

@Test public void basics() throws Exception {
// Timeline (A has concurrency 2, B 1):
// #1 o-A--------------B-----------------o
@@ -118,6 +132,7 @@
e2.waitForSuspension();
e3.waitForSuspension();
story.j.assertBuildStatus(Result.NOT_BUILT, story.j.waitForCompletion(b2));
story.j.assertLogContains(Messages.StageStepExecution_non_block_mode_deprecated(), b2);
InterruptedBuildAction iba = b2.getAction(InterruptedBuildAction.class);
assertNotNull(iba);
List<CauseOfInterruption> causes = iba.getCauses();
@@ -148,6 +163,7 @@
e1.waitForSuspension();
assertFalse(b1.isBuilding());
assertEquals(Result.SUCCESS, b1.getResult());
story.j.assertLogContains(Messages.StageStepExecution_non_block_mode_deprecated(), b1);
e3.waitForSuspension();
assertTrue(b3.isBuilding());
story.j.assertLogContains("done", b1);
@@ -158,6 +174,7 @@
assertFalse(b3.isBuilding());
assertEquals(Result.SUCCESS, b3.getResult());
story.j.assertLogContains("done", b3);
story.j.assertLogContains(Messages.StageStepExecution_non_block_mode_deprecated(), b3);
}
});
}

0 comments on commit d6a220b

Please sign in to comment.
You can’t perform that action at this time.