Declarative vs. Scripting Processing Failures

I see on the declarative pipeline that it is really through the "post" section very simple with conditions such as "always", "failure", ...:

https://jenkins.io/doc/book/pipeline/syntax/#post

But with Scripted Pipeline there are no examples of how to do this:

This link gives an example, but only for the "always" condition

https://jenkins.io/doc/book/pipeline/jenkinsfile/#handling-failures

I see these documents on how to set this result, but I do not understand, because with Declarative Pipeline you do not need to install it manually, the commands provided by the plugins handle this for you.

https://support.cloudbees.com/hc/en-us/articles/218554077-How-to-set-current-build-result-in-Pipeline

Can anyone help me with this?

For example, if I do this:

node {try {error "Test error"} catch (ex) {echo 'Error handleled'}}

It does not call the FAILURE build status automatically, and I do not see the echo. Why?

+4
source share
1 answer

Your piece of code works as expected:

node { try { error 'Test error' } catch (ex) { echo 'Error handled' } }

gives:

[Pipeline] node
Running on maître in /var/lib/jenkins/workspace/test-pipeline2
[Pipeline] {
[Pipeline] error
[Pipeline] echo
Error handled
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS

Explanations:

, catch. catchError . .: https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#code-catcherror-code-catch-error-and-set-build-result

+1

Source: https://habr.com/ru/post/1672584/


All Articles