Skip to content
Permalink
Browse files

Merge pull request #11 from abayer/jenkins-38097

[JENKINS-38097] Run empty stages for post-failure stages.
  • Loading branch information
abayer committed Sep 13, 2016
2 parents 4604f74 + 1328296 commit 15079563fca0f5eb688510bacc6086b7e2fefbed
@@ -64,31 +64,33 @@ public class ModelInterpreter implements Serializable {
// We save the caught error, if any, for throwing at the end of the build.
nodeOrDockerOrNone(root.agent) {
toolsBlock(root.agent, root.tools) {
try {
catchRequiredContextForNode(root.agent) {
// If we have an agent and script.scm isn't null, run checkout scm
if (root.agent.hasAgent() && Utils.hasScmContext(script)) {
script.checkout script.scm
}

for (int i = 0; i < root.stages.getStages().size(); i++) {
Stage thisStage = root.stages.getStages().get(i)
// If we have an agent and script.scm isn't null, run checkout scm
if (root.agent.hasAgent() && Utils.hasScmContext(script)) {
script.checkout script.scm
}

script.stage(thisStage.name) {
Closure closureToCall = thisStage.closureWrapper.closure
closureToCall.delegate = script
closureToCall.resolveStrategy = Closure.DELEGATE_FIRST
closureToCall.call()
for (int i = 0; i < root.stages.getStages().size(); i++) {
Stage thisStage = root.stages.getStages().get(i)

script.stage(thisStage.name) {
if (firstError == null) {
try {
catchRequiredContextForNode(root.agent) {
Closure closureToCall = thisStage.closureWrapper.closure
closureToCall.delegate = script
closureToCall.resolveStrategy = Closure.DELEGATE_FIRST
closureToCall.call()
}.call()
} catch (Exception e) {
script.echo "Error in stages execution: ${e.getMessage()}"
script.getProperty("currentBuild").result = Result.FAILURE
if (firstError == null) {
firstError = e
}
}
}
}
}.call()
} catch (Exception e) {
script.echo "Error in stages execution: ${e.getMessage()}"
script.getProperty("currentBuild").result = Result.FAILURE
if (firstError == null) {
firstError = e
}
}

try {
catchRequiredContextForNode(root.agent) {
@@ -30,6 +30,7 @@
import org.apache.commons.io.IOUtils;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -108,6 +109,18 @@ public void twoStagePipeline() throws Exception {
j.assertLogContains("goodbye", b);
}

@Issue("JENKINS-38097")
@Test
public void allStagesExist() throws Exception {
prepRepoWithJenkinsfile("allStagesExist");

WorkflowRun b = getAndStartBuild();
j.assertBuildStatus(Result.FAILURE, j.waitForCompletion(b));
j.assertLogContains("[Pipeline] { (foo)", b);
j.assertLogContains("hello", b);
j.assertLogContains("[Pipeline] { (bar)", b);
}

@Test
public void validStepParameters() throws Exception {
prepRepoWithJenkinsfile("validStepParameters");
@@ -0,0 +1,38 @@
/*
* The MIT License
*
* Copyright (c) 2016, 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("foo") {
error "hello"
}
stage("bar") {
echo "goodbye"
}
}
}



0 comments on commit 1507956

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