Skip to content
Permalink
Browse files
Merge pull request #214 from abayer/jenkins-47783
[JENKINS-47783] Verify skipped stage status for parallel stages
  • Loading branch information
abayer committed Nov 8, 2017
2 parents f567261 + deb5574 commit c643a64165d5b7bed0dfa8a53cdda58ed0bf2a58
@@ -196,6 +196,21 @@ public void parallelStagesHaveStatusAndPost() throws Exception {
assertEquals(GenericStatus.FAILURE, StatusAndTiming.computeChunkStatus(b, null, startFirst, endFirst, null));
assertNotNull(endFirst.getError());

FlowNode startThird = scanner.findFirstMatch(heads, null, Utils.isStageWithOptionalName("third"));
assertNotNull(startThird);
assertTrue(startThird instanceof BlockStartNode);
FlowNode endThird = scanner.findFirstMatch(heads, null, Utils.endNodeForStage((BlockStartNode)startThird));
assertNotNull(endThird);
assertEquals(GenericStatus.FAILURE, StatusAndTiming.computeChunkStatus(b, null, startThird, endThird, null));

TagsAction thirdTags = startThird.getAction(TagsAction.class);
assertNotNull(thirdTags);
assertNotNull(thirdTags.getTags());
assertFalse(thirdTags.getTags().isEmpty());
assertTrue(thirdTags.getTags().containsKey(Utils.getStageStatusMetadata().getTagName()));
assertEquals(StageStatus.getSkippedForConditional(),
thirdTags.getTags().get(Utils.getStageStatusMetadata().getTagName()));

TagsAction nestedTags = startFirst.getAction(TagsAction.class);
assertNotNull(nestedTags);
assertNotNull(nestedTags.getTags());
@@ -1156,4 +1171,68 @@ public void parallelStagesFailFast() throws Exception {
.hasFailureCase()
.go();
}

@Issue("JENKINS-47783")
@Test
public void parallelStagesHaveStatusWhenSkipped() throws Exception {
WorkflowRun b = expect(Result.FAILURE, "parallelStagesHaveStatusWhenSkipped")
.logContains("[Pipeline] { (bar)",
"[Pipeline] { (foo)",
"[first] { (Branch: first)",
"[Pipeline] [first] { (first)",
"[second] { (Branch: second)",
"[Pipeline] [second] { (second)")
.hasFailureCase()
.go();

FlowExecution execution = b.getExecution();
List<FlowNode> heads = execution.getCurrentHeads();
DepthFirstScanner scanner = new DepthFirstScanner();
FlowNode startFoo = scanner.findFirstMatch(heads, null, Utils.isStageWithOptionalName("foo"));
assertNotNull(startFoo);
assertTrue(startFoo instanceof BlockStartNode);
FlowNode endFoo = scanner.findFirstMatch(heads, null, Utils.endNodeForStage((BlockStartNode)startFoo));
assertNotNull(endFoo);
assertEquals(GenericStatus.FAILURE, StatusAndTiming.computeChunkStatus(b, null, startFoo, endFoo, null));
assertNotNull(endFoo.getError());

FlowNode startFirst = scanner.findFirstMatch(heads, null, Utils.isStageWithOptionalName("first"));
assertNotNull(startFirst);
assertTrue(startFirst instanceof BlockStartNode);
FlowNode endFirst = scanner.findFirstMatch(heads, null, Utils.endNodeForStage((BlockStartNode)startFirst));
assertNotNull(endFirst);
assertEquals(GenericStatus.FAILURE, StatusAndTiming.computeChunkStatus(b, null, startFirst, endFirst, null));

FlowNode startSecond = scanner.findFirstMatch(heads, null, Utils.isStageWithOptionalName("second"));
assertNotNull(startSecond);
assertTrue(startSecond instanceof BlockStartNode);
FlowNode endSecond = scanner.findFirstMatch(heads, null, Utils.endNodeForStage((BlockStartNode)startSecond));
assertNotNull(endSecond);
assertEquals(GenericStatus.FAILURE, StatusAndTiming.computeChunkStatus(b, null, startSecond, endSecond, null));

TagsAction firstTags = startFirst.getAction(TagsAction.class);
assertNotNull(firstTags);
assertNotNull(firstTags.getTags());
assertFalse(firstTags.getTags().isEmpty());
assertTrue(firstTags.getTags().containsKey(Utils.getStageStatusMetadata().getTagName()));
assertEquals(StageStatus.getSkippedForFailure(),
firstTags.getTags().get(Utils.getStageStatusMetadata().getTagName()));

TagsAction secondTags = startSecond.getAction(TagsAction.class);
assertNotNull(secondTags);
assertNotNull(secondTags.getTags());
assertFalse(secondTags.getTags().isEmpty());
assertTrue(secondTags.getTags().containsKey(Utils.getStageStatusMetadata().getTagName()));
assertEquals(StageStatus.getSkippedForFailure(),
secondTags.getTags().get(Utils.getStageStatusMetadata().getTagName()));

TagsAction parentTags = startFoo.getAction(TagsAction.class);
assertNotNull(parentTags);
assertNotNull(parentTags.getTags());
assertFalse(parentTags.getTags().isEmpty());
assertTrue(parentTags.getTags().containsKey(Utils.getStageStatusMetadata().getTagName()));
assertEquals(StageStatus.getSkippedForFailure(),
parentTags.getTags().get(Utils.getStageStatusMetadata().getTagName()));
}

}
@@ -47,6 +47,16 @@ pipeline {
}
}
}
stage("third") {
when {
expression {
return false
}
}
steps {
echo "Third branch"
}
}
}
post {
failure {
@@ -0,0 +1,52 @@
/*
* The MIT License
*
* Copyright (c) 2017, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

pipeline {
agent none
stages {
stage("bar") {
steps {
error "Fail out"
}
}
stage("foo") {
parallel {
stage("first") {
steps {
echo "First branch"
}
}
stage("second") {
steps {
echo "Second branch"
}
}
}
}
}
}




0 comments on commit c643a64

Please sign in to comment.