Skip to content

Commit

Permalink
[FIXED JENKINS-50645] Move failure to run after other status checks
Browse files Browse the repository at this point in the history
This way failure will still evaluate even if the actual failure
doesn't occur until in the success or unstable blocks.
  • Loading branch information
abayer committed Apr 17, 2018
1 parent 2249ecb commit 7e0eaf4
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 3 deletions.
Expand Up @@ -36,7 +36,7 @@ import javax.annotation.Nonnull
*
* @author Andrew Bayer
*/
@Extension(ordinal=700d) @Symbol("failure")
@Extension(ordinal=500d) @Symbol("failure")
class Failure extends BuildCondition {
@Override
boolean meetsCondition(@Nonnull WorkflowRun r) {
Expand Down
Expand Up @@ -36,7 +36,7 @@ import javax.annotation.Nonnull
*
* @author Andrew Bayer
*/
@Extension(ordinal=600d) @Symbol("success")
@Extension(ordinal=700d) @Symbol("success")
class Success extends BuildCondition {
@Override
boolean meetsCondition(@Nonnull WorkflowRun r) {
Expand Down
Expand Up @@ -36,7 +36,7 @@ import javax.annotation.Nonnull
*
* @author Andrew Bayer
*/
@Extension(ordinal=500d) @Symbol("unstable")
@Extension(ordinal=600d) @Symbol("unstable")
class Unstable extends BuildCondition {
@Override
boolean meetsCondition(@Nonnull WorkflowRun r) {
Expand Down
Expand Up @@ -72,6 +72,26 @@ public void postChecksAllConditions() throws Exception {
.go();
}

@Issue("JENKINS-50645")
@Test
public void postFailureAfterSuccess() throws Exception {
// NOTE: Not checking log in order because "I AM FAILING NOW" doesn't actually show up until the end of the Pipeline.
// That's expected/normal behavior for the error step.
expect(Result.FAILURE, "postFailureAfterSuccess")
.logContains("I AM FAILING NOW", "I FAILED")
.go();
}

@Issue("JENKINS-50645")
@Test
public void postFailureAfterUnstable() throws Exception {
// NOTE: Not checking log in order because "I AM FAILING NOW" doesn't actually show up until the end of the Pipeline.
// That's expected/normal behavior for the error step.
expect(Result.FAILURE, "postFailureAfterUnstable")
.logContains("I AM FAILING NOW", "I FAILED")
.go();
}

@Test
public void postOnChanged() throws Exception {
WorkflowRun b = getAndStartNonRepoBuild("postOnChangeFailed");
Expand Down
@@ -0,0 +1,45 @@
/*
* The MIT License
*
* Copyright (c) 2018, 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") {
steps {
echo "hello"
}
}
}
post {
success {
error "I AM FAILING NOW"
}
failure {
echo "I FAILED"
}
}
}



@@ -0,0 +1,48 @@
/*
* The MIT License
*
* Copyright (c) 2018, 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") {
steps {
echo "hello"
script {
currentBuild.result = "UNSTABLE"
}
}
}
}
post {
unstable {
error "I AM FAILING NOW"
}
failure {
echo "I FAILED"
}
}
}



0 comments on commit 7e0eaf4

Please sign in to comment.