If I surround a General build step (as described in the snippet generator) in a try-catch block, within a scripted Jenkins file, the error is not caught.
for example I expected the following code block to mark the build as unstable. But an error is thrown at the archiveArtifacts step.
node(){ stage('Failing Archive'){ try{ archiveArtifacts 'non existent path' } catch (err) { echo 'Archive failed!' currentBuild.result = 'UNSTABLE' } } }
EDIT (abayer): More generally - CoreStep executions of a SimpleBuildStep (such as archiveArtifacts, which is actually calling the ArtifactArchiver publisher from core), only throw an exception if the SimpleBuildStep itself throws an exception. And as a general rule, failure-but-not-error cases (like the non-existent path case here) of a SimpleBuildStep don't throw an exception, since the FreeStyleBuild they were initially used in would proceed anyway (especially in the case of publishers/recorders, which are the most common SimpleBuildStep implementations), after having set the build status.
- causes
-
JENKINS-51913 Post-build action "Archive the artifacts" prints exception to console when no artifacts found (regression in 2.108)
-
- Closed
-
- is duplicated by
-
JENKINS-45200 Archiving artifacts fails, but build step is shown with a green dot
-
- Resolved
-
-
JENKINS-44407 archiveArtifacts step failure is not displayed
-
- Closed
-
- is related to
-
JENKINS-51913 Post-build action "Archive the artifacts" prints exception to console when no artifacts found (regression in 2.108)
-
- Closed
-
- relates to
-
JENKINS-31931 archive step sets result to FAILURE but does not fail the job
-
- Resolved
-
- links to
[JENKINS-47142] archiveArtifacts step failure is not displayed
Component/s | Original: core [ 15593 ] |
Link |
New:
This issue is duplicated by |
Component/s | New: workflow-basic-steps-plugin [ 21712 ] | |
Component/s | Original: pipeline [ 21692 ] |
Summary | Original: Try-catch doesn't catch errors from general build steps | New: CoreStep execution of SimpleBuildSteps doesn't actually fail in Pipeline |
Assignee | New: Andrew Bayer [ abayer ] |
Description |
Original:
If I surround a General build step (as described in the snippet generator) in a try-catch block, within a scripted Jenkins file, the error is not caught. for example I expected the following code block to mark the build as unstable. But an error is thrown at the archiveArtifacts step. {code:java} node(){ stage('Failing Archive'){ try{ archiveArtifacts 'non existent path' } catch (err) { echo 'Archive failed!' currentBuild.result = 'UNSTABLE' } } } {code} |
New:
If I surround a General build step (as described in the snippet generator) in a try-catch block, within a scripted Jenkins file, the error is not caught. for example I expected the following code block to mark the build as unstable. But an error is thrown at the archiveArtifacts step. {code:java} node(){ stage('Failing Archive'){ try{ archiveArtifacts 'non existent path' } catch (err) { echo 'Archive failed!' currentBuild.result = 'UNSTABLE' } } } {code} EDIT (abayer): More generally - {{CoreStep}} executions of a {{SimpleBuildStep}} (such as {{archiveArtifacts}}, which is actually calling the {{ArtifactArchiver}} publisher from core), only throw an exception if the {{SimpleBuildStep}} itself throws an exception. And as a general rule, failure-but-not-error cases (like the non-existent path case here) of a {{SimpleBuildStep}} don't throw an exception, since the {{FreeStyleBuild}} they were initially used in would proceed anyway (especially in the case of publishers/recorders, which are the most common {{SimpleBuildStep}} implementations), after having set the build status. |
Link |
New:
This issue relates to |
Component/s | New: core [ 15593 ] | |
Component/s | Original: workflow-basic-steps-plugin [ 21712 ] |
Assignee | Original: Andrew Bayer [ abayer ] | New: Jesse Glick [ jglick ] |
Status | Original: Open [ 1 ] | New: In Progress [ 3 ] |