-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JENKINS-49997 - Added Unsuccessful build condition for _post_
- Loading branch information
Showing
4 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
...roovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/conditions/Unsuccessful.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* 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. | ||
*/ | ||
package org.jenkinsci.plugins.pipeline.modeldefinition.model.conditions | ||
|
||
import hudson.Extension | ||
import hudson.model.Result | ||
import org.jenkinsci.Symbol | ||
import org.jenkinsci.plugins.pipeline.modeldefinition.model.BuildCondition | ||
import org.jenkinsci.plugins.workflow.job.WorkflowRun | ||
|
||
import javax.annotation.Nonnull | ||
|
||
/** | ||
* A {@link BuildCondition} for matching unstable builds. | ||
* | ||
* @author Andrew Bayer | ||
*/ | ||
@Extension(ordinal=650d) @Symbol("unsuccessful") | ||
class Unsuccessful extends BuildCondition { | ||
@Deprecated | ||
@Override | ||
boolean meetsCondition(@Nonnull WorkflowRun r) { | ||
return meetsCondition(r, null, null) | ||
} | ||
|
||
@Override | ||
boolean meetsCondition(@Nonnull WorkflowRun r, Object context, Throwable error) { | ||
return isNotNull(r) || ! is(r, Result.SUCCESS) | ||
} | ||
|
||
private boolean isNotNull(WorkflowRun r){ | ||
return r.getResult() != null && getExecutionResult(r) != null | ||
} | ||
|
||
private boolean is(WorkflowRun r, Result res){ | ||
Result execResult = getExecutionResult(r) | ||
return execResult == res || r.getResult() == res | ||
} | ||
|
||
@Override | ||
String getDescription() { | ||
return Messages.Unsuccessful_Description() | ||
} | ||
|
||
static final long serialVersionUID = 1L | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
pipeline-model-definition/src/test/resources/postStage/unsuccessful.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* 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 { | ||
label "here" | ||
} | ||
stages { | ||
stage("foo") { | ||
steps { | ||
echo "hello" | ||
script { | ||
String res = env.MAKE_RESULT | ||
if (res != null) { | ||
echo "Setting build result ${res}" | ||
currentBuild.result = res | ||
// JENKINS-52114 - can't tell the difference between setting currentBuild.result in this stage | ||
// and an error in a parallel stage, so let's error. | ||
if (res == "FAILURE") { | ||
error "Failing explicitly" | ||
} | ||
} else { | ||
echo "All is well" | ||
} | ||
} | ||
} | ||
post { | ||
unsuccessful { | ||
echo "I FAILED YOU, SORRY" | ||
} | ||
unstable { | ||
echo "I AM UNSTABLE" | ||
} | ||
always { | ||
echo "I LOVE YOU VIRGINIA" | ||
} | ||
} | ||
} | ||
} | ||
post { | ||
always { | ||
echo "And AAAAIIIAAAIAI" | ||
} | ||
} | ||
} |