Skip to content

Commit

Permalink
[FIXED JENKINS-26107] stage may now take a block; the original mode i…
Browse files Browse the repository at this point in the history
…s deprecated.
  • Loading branch information
jglick committed May 12, 2016
1 parent 4711a80 commit 114b000
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 64 deletions.
7 changes: 6 additions & 1 deletion pom.xml
Expand Up @@ -49,7 +49,12 @@
<dependency> <dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId> <groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId> <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> <classifier>tests</classifier>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
Expand Down
Expand Up @@ -63,6 +63,10 @@ public DescriptorImpl() {
return "Stage"; return "Stage";
} }


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

} }


} }
Expand Up @@ -34,6 +34,7 @@
import org.jenkinsci.plugins.workflow.graph.FlowNode; import org.jenkinsci.plugins.workflow.graph.FlowNode;
import org.jenkinsci.plugins.workflow.graph.FlowStartNode; import org.jenkinsci.plugins.workflow.graph.FlowStartNode;
import org.jenkinsci.plugins.workflow.steps.AbstractStepExecutionImpl; 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.FlowInterruptedException;
import org.jenkinsci.plugins.workflow.steps.StepContext; import org.jenkinsci.plugins.workflow.steps.StepContext;
import org.jenkinsci.plugins.workflow.steps.StepContextParameter; import org.jenkinsci.plugins.workflow.steps.StepContextParameter;
Expand All @@ -46,7 +47,6 @@ public class StageStepExecution extends AbstractStepExecutionImpl {
@Inject(optional=true) private transient StageStep step; @Inject(optional=true) private transient StageStep step;
@StepContextParameter private transient Run<?,?> run; @StepContextParameter private transient Run<?,?> run;
@StepContextParameter private transient FlowNode node; @StepContextParameter private transient FlowNode node;
@StepContextParameter private transient TaskListener listener; // picked up by getRequiredContext


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


@Override @Override
public boolean start() throws Exception { 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)) { if (isInsideParallel(node)) {
throw new AbortException(Messages.StageStepExecution_the_stage_step_must_not_be_used_inside_a()); throw new AbortException(Messages.StageStepExecution_the_stage_step_must_not_be_used_inside_a());
} }
Expand Down
Expand Up @@ -28,7 +28,4 @@ THE SOFTWARE.
<f:entry field="name" title="Stage Name"> <f:entry field="name" title="Stage Name">
<f:textbox/> <f:textbox/>
</f:entry> </f:entry>
<f:entry field="concurrency" title="Concurrency">
<f:number clazz="positive-number"/>
</f:entry>
</j:jelly> </j:jelly>

This file was deleted.

@@ -1,6 +1,5 @@
<div> <div>
By default, Pipeline builds can run concurrently. Creates a labeled block.
The stage command lets you mark certain sections of a build as being constrained by limited concurrency. <p>
Newer builds are always given priority when entering such a throttled stage; older builds will simply exit early if An older, deprecated mode of this step did not take a block argument, and accepted a <code>concurrency</code> parameter.
they are preempted.
</div> </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.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.

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

0 comments on commit 114b000

Please sign in to comment.