Skip to content
Permalink
Browse files

Merge pull request #225 from abayer/jenkins-48266

[FIXED JENKINS-48266] Skip post for skipped parallel stages
  • Loading branch information...
abayer committed Dec 4, 2017
2 parents f26ad78 + 8e18c35 commit 32c5e4178c89faca3ad184b4030d8f403425bdac
@@ -176,18 +176,21 @@ class ModelInterpreter implements Serializable {

def evaluateStage(Root root, Agent parentAgent, Stage thisStage, Throwable firstError, Stage parentStage = null) {
return {
def isSkipped = false
def thisError = null
script.stage(thisStage.name) {
try {
if (firstError != null) {
Utils.logToTaskListener("Stage '${thisStage.name}' skipped due to earlier failure(s)")
Utils.markStageSkippedForFailure(thisStage.name)
isSkipped = true
if (thisStage.parallel != null) {
script.parallel(getParallelStages(root, parentAgent, thisStage, firstError, parentStage, true, false, false))
}
} else if (skipUnstable(root.options)) {
Utils.logToTaskListener("Stage '${thisStage.name}' skipped due to earlier stage(s) marking the build as unstable")
Utils.markStageSkippedForUnstable(thisStage.name)
isSkipped = true
if (thisStage.parallel != null) {
script.parallel(getParallelStages(root, parentAgent, thisStage, firstError, parentStage, false, true, false))
}
@@ -202,6 +205,7 @@ class ModelInterpreter implements Serializable {
} else {
Utils.logToTaskListener("Stage '${thisStage.name}' skipped due to when conditional")
Utils.markStageSkippedForConditional(thisStage.name)
isSkipped = true
script.parallel(getParallelStages(root, parentAgent, thisStage, firstError, parentStage, false, false, true))
}
} else {
@@ -218,6 +222,7 @@ class ModelInterpreter implements Serializable {
} else {
Utils.logToTaskListener("Stage '${thisStage.name}' skipped due to when conditional")
Utils.markStageSkippedForConditional(thisStage.name)
isSkipped = true
}
}
}
@@ -231,10 +236,7 @@ class ModelInterpreter implements Serializable {
thisError = e
} finally {
// And finally, run the post stage steps if this was a parallel parent.
// JENKINS-47928: Do not run if the error was not thrown from this stage
if (thisError != null &&
thisStage.parallel != null &&
root.hasSatisfiedConditions(thisStage.post, script.getProperty("currentBuild"))) {
if (!isSkipped && thisStage.parallel != null && root.hasSatisfiedConditions(thisStage.post, script.getProperty("currentBuild"))) {
Utils.logToTaskListener("Post stage")
firstError = runPostConditions(thisStage.post, thisStage.agent ?: parentAgent, firstError, thisStage.name)
}
@@ -26,6 +26,7 @@
import hudson.model.Result;
import hudson.model.Slave;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;

@@ -121,14 +122,22 @@ public void withAgentNoneAndAgentAny() throws Exception {
expect("withAgentNoneAndAgentAny")
.logNotContains("Required context class hudson.FilePath is missing").go();
}

@Issue("JENKINS-47928")
@Test
public void parallelParentPostFailure() throws Exception {
expect(Result.FAILURE, "parallelParentPostFailure")
.logNotContains("PARALLEL STAGE POST").go();
}

@Issue("JENKINS-48266")
@Test
public void postAfterParallel() throws Exception {
expect("postAfterParallel")
.logContains("Post ran")
.go();
}

@Override
protected ExpectationsBuilder expect(String resource) {
return super.expect("postStage", resource);
@@ -0,0 +1,46 @@
/*
* 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('Parallel') {
parallel {
stage('Child 1') {
agent any
steps { echo 'Child 1' }
}
stage('Child 2') {
agent any
steps { echo 'Child 2' }
}
}
post {
always {
echo 'Post ran'
}
}
}
}
}

0 comments on commit 32c5e41

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