Last active
January 6, 2021 12:43
-
-
Save ederparaiso/f88c64713dbaa2c5c74a433186cd741a to your computer and use it in GitHub Desktop.
Sample jenkins result examples
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
// https://javadoc.jenkins-ci.org/hudson/model/Result.html | |
/* | |
ABORTED - The build was manually aborted. | |
FAILURE - The build had a fatal error. | |
NOT_BUILT - The module was not built. | |
SUCCESS - The build had no errors. | |
UNSTABLE - The build had some errors but they were not fatal. | |
*/ | |
pipeline { | |
agent any | |
stages { | |
stage('Clean ws') { | |
steps { | |
cleanWs() | |
} | |
} | |
stage('Mark stage as aborted') { | |
steps { | |
script { | |
echo 'This stage will be marked as ABORTED' | |
catchError(buildResult: 'SUCCESS', stageResult: 'ABORTED') { | |
// if for some reason you want to mark a stage as aborted then throw and catch an error | |
sh 'exit 1' | |
} | |
} | |
} | |
} | |
stage('Error job') { | |
steps { | |
script { | |
echo 'This stage will fail and marked as FAILED' | |
catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE') { | |
build(job: 'ErrorJob', wait: true) | |
} | |
} | |
} | |
} | |
stage('Error job without propagation') { | |
steps { | |
script { | |
echo 'This stage will NOT fail due to propagate = false, but will force to fail and marked as UNSTABLE' | |
catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE') { | |
def r = build(job: 'ErrorJob', wait: true, propagate: false) | |
if (r.result == 'FAILURE'){ | |
sh 'exit 1' | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
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
// https://javadoc.jenkins-ci.org/hudson/model/Result.html | |
/* | |
ABORTED - The build was manually aborted. | |
FAILURE - The build had a fatal error. | |
NOT_BUILT - The module was not built. | |
SUCCESS - The build had no errors. | |
UNSTABLE - The build had some errors but they were not fatal. | |
*/ | |
pipeline { | |
agent any | |
stages { | |
stage('Clean ws') { | |
steps { | |
cleanWs() | |
} | |
} | |
stage('Init') { | |
steps { | |
echo 'Init stage' | |
} | |
} | |
stage('Choice') { | |
steps { | |
script { | |
echo "Choice: ${PIPE_TYPE}" | |
if("SUCCESS" == "${PIPE_TYPE}"){ | |
echo 'Success choice' | |
} else if("FAIL" == "${PIPE_TYPE}") { | |
error 'Fail choice' | |
} else if("ABORT" == "${PIPE_TYPE}") { | |
currentBuild.result = 'ABORTED' | |
} else if("UNSTABLE" == "${PIPE_TYPE}") { | |
unstable 'Unstable choice' | |
} | |
} | |
} | |
} | |
stage('Finish') { | |
steps { | |
script { | |
// skip stages if result was set previously | |
if(!currentBuild.result) | |
return | |
echo 'Finish stage' | |
} | |
} | |
} | |
} | |
} |
Author
ederparaiso
commented
Dec 12, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment