Skip to content

Commit

Permalink
Merge pull request #5 from jenkinsci/block-step-JENKINS-26107
Browse files Browse the repository at this point in the history
[JENKINS-26107] stage may now take a block
  • Loading branch information
svanoort committed Aug 30, 2016
2 parents 4711a80 + d7b9a5f commit d6a220b
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 66 deletions.
11 changes: 8 additions & 3 deletions pom.xml
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
Expand Up @@ -63,6 +63,10 @@ public DescriptorImpl() {
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.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;
Expand All @@ -46,7 +47,6 @@ public class StageStepExecution extends AbstractStepExecutionImpl {
@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;
Expand All @@ -60,6 +60,14 @@ private static final class StageActionImpl extends InvisibleAction implements St

@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());
}
Expand Down
Expand Up @@ -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.

Expand Up @@ -53,6 +53,20 @@ public class StageStepTest {
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
Expand Down Expand Up @@ -118,6 +132,7 @@ public class StageStepTest {
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();
Expand Down Expand Up @@ -148,6 +163,7 @@ public class StageStepTest {
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);
Expand All @@ -158,6 +174,7 @@ public class StageStepTest {
assertFalse(b3.isBuilding());
assertEquals(Result.SUCCESS, b3.getResult());
story.j.assertLogContains("done", b3);
story.j.assertLogContains(Messages.StageStepExecution_non_block_mode_deprecated(), b3);
}
});
}
Expand Down

0 comments on commit d6a220b

Please sign in to comment.