Skip to content

Commit

Permalink
[FIXED JENKINS-37663] Check execution result in post as well
Browse files Browse the repository at this point in the history
The new junit step doesn't set the Run to UNSTABLE directly, it sets
the context (and therefore the execution) result to UNSTABLE. We
should be checking the execution result as well as the Run result.
  • Loading branch information
abayer committed Nov 20, 2017
1 parent 91011f0 commit d533dd5
Show file tree
Hide file tree
Showing 12 changed files with 429 additions and 8 deletions.
5 changes: 5 additions & 0 deletions pipeline-model-definition/pom.xml
Expand Up @@ -213,6 +213,11 @@
<artifactId>jcabi-matchers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down
Expand Up @@ -38,7 +38,9 @@ import org.jenkinsci.plugins.workflow.job.WorkflowRun
public class Aborted extends BuildCondition {
@Override
public boolean meetsCondition(WorkflowRun r) {
return r.getResult() != null && r.getResult().equals(Result.ABORTED)
Result execResult = getExecutionResult(r)
return (execResult != null && execResult.equals(Result.ABORTED)) ||
(r.getResult() != null && r.getResult().equals(Result.ABORTED))
}

@Override
Expand Down
Expand Up @@ -38,6 +38,7 @@ import org.jenkinsci.plugins.workflow.job.WorkflowRun
public class Changed extends BuildCondition {
@Override
public boolean meetsCondition(WorkflowRun r) {
Result execResult = getExecutionResult(r)
// Only look at the previous completed build.
WorkflowRun prev = r.getPreviousCompletedBuild()
// If there's no previous build, we're inherently changed.
Expand All @@ -46,11 +47,13 @@ public class Changed extends BuildCondition {
}
// If the current build's result isn't null (i.e., it's got a specified status), and it's different than the
// previous build's result, we're changed.
else if (r.getResult() != null && !prev.getResult().equals(r.getResult())) {
else if ((execResult != null && !prev.getResult().equals(execResult)) ||
(r.getResult() != null && !prev.getResult().equals(r.getResult()))) {
return true
}
// If the current build's result is null and the previous build's result is not SUCCESS, we're changed.
else if (r.getResult() == null && !prev.getResult().equals(Result.SUCCESS)) {
else if ((execResult == Result.SUCCESS && !prev.getResult().equals(Result.SUCCESS)) ||
(r.getResult() == null && !prev.getResult().equals(Result.SUCCESS))) {
return true
}
// And in any other condition, we're not changed, so return false.
Expand Down
Expand Up @@ -38,7 +38,9 @@ import org.jenkinsci.plugins.workflow.job.WorkflowRun
public class Failure extends BuildCondition {
@Override
public boolean meetsCondition(WorkflowRun r) {
return r.getResult() != null && r.getResult().equals(Result.FAILURE)
Result execResult = getExecutionResult(r)
return (execResult != null && execResult.equals(Result.FAILURE)) ||
(r.getResult() != null && r.getResult().equals(Result.FAILURE))
}

@Override
Expand Down
Expand Up @@ -38,7 +38,9 @@ import org.jenkinsci.plugins.workflow.job.WorkflowRun
public class NotBuilt extends BuildCondition {
@Override
public boolean meetsCondition(WorkflowRun r) {
return r.getResult() != null && r.getResult().equals(Result.NOT_BUILT)
Result execResult = getExecutionResult(r)
return (execResult != null && execResult.equals(Result.NOT_BUILT)) ||
(r.getResult() != null && r.getResult().equals(Result.NOT_BUILT))
}

@Override
Expand Down
Expand Up @@ -38,7 +38,9 @@ import org.jenkinsci.plugins.workflow.job.WorkflowRun
public class Success extends BuildCondition {
@Override
public boolean meetsCondition(WorkflowRun r) {
return r.getResult() == null || r.getResult().isBetterOrEqualTo(Result.SUCCESS)
Result execResult = getExecutionResult(r)
return (execResult == null || execResult.isBetterOrEqualTo(Result.SUCCESS)) &&
(r.getResult() == null || r.getResult().isBetterOrEqualTo(Result.SUCCESS))
}

@Override
Expand Down
Expand Up @@ -38,7 +38,9 @@ import org.jenkinsci.plugins.workflow.job.WorkflowRun
public class Unstable extends BuildCondition {
@Override
public boolean meetsCondition(WorkflowRun r) {
return r.getResult() != null && r.getResult().equals(Result.UNSTABLE)
Result execResult = getExecutionResult(r)
return (execResult != null && execResult.equals(Result.UNSTABLE)) ||
(r.getResult() != null && r.getResult().equals(Result.UNSTABLE))
}

@Override
Expand Down
Expand Up @@ -197,4 +197,14 @@ public void abortedFlowInterruptedException() throws Exception {

j.assertLogContains("Job aborted due to input", run);
}

@Issue("JENKINS-37663")
@Test
public void contextResultOverridesRunResult() throws Exception {
expect(Result.UNSTABLE, "contextResultOverridesRunResult")
.otherResource("junitResult.xml", "junitResult.xml")
.logContains("I AM UNSTABLE")
.logNotContains("MOST DEFINITELY FINISHED")
.go();
}
}
@@ -0,0 +1,48 @@
/*
* 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 any
stages {
stage("foo") {
steps {
echo "hello"
}
}
}
post {
always {
junit allowEmptyResults: true, testResults: 'junitResult.xml'
}
success {
echo "MOST DEFINITELY FINISHED"
}
unstable {
echo "I AM UNSTABLE"
}
}
}



0 comments on commit d533dd5

Please sign in to comment.