groovy - How to perform actions for failed builds in Jenkinsfile -


is there way perform cleanup (or rollback) if build in jenkinsfile failed?

i inform our atlassian stash instance build failed (by doing curl @ correct url).

basically post step when build status set fail.

should use try {} catch ()? if so, exception type should catch?

i'm searching solution problem. far best come create wrapper function runs pipeline code in try catch block. if want notify on success can store exception in variable , move notification code block. note have rethrow exception jenkins considers build failed. maybe reader finds more elegant approach problem.

pipeline('linux') {     stage 'pull'     stage 'deploy'     echo "deploying"     throw new filenotfoundexception("nothing pull")     // ...  }   def pipeline(string label, closure body) {      node(label) {         wrap([$class: 'timestamperbuildwrapper']) {             try {                 body.call()             } catch (exception e) {                 emailext subject: "${env.job_name} - build # ${env.build_number} - failure (${e.message})!", to: "me@me.com",body: "..."                 throw e; // rethrow build considered failed                                     }          }     } } 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -