jenkins notifying error occured in different steps by sending mail in Pipeline (former known as Workflow)

后端 未结 3 1170
长情又很酷
长情又很酷 2020-12-06 13:20

I have a pipeline with multiple steps, for example:

stage \'dev - compile\'
node(\'master\') {
  //do something
}

stage \'test- compile\'
node(\'master\') {         


        
3条回答
  •  醉话见心
    2020-12-06 13:48

    Well, your idea is absolutely correct, you just need to move mail after the catch block or use finally. Examples (in pseudocode):

    try {
        //code
        email = 'success'
    } catch(Exception e) { 
        // error handler: logging
        email = 'failure'
    }
    send email
    

    Or the same approach using the catchError pipeline built-in:

    result = 'failure'
    catchError { // this catches all exceptions and set the build result
        //code
        result = 'success' // we will reach this point only if no exception was thrown
    }
    send result 
    

    Or using finally:

    try {
        //code
    } finally { 
        send email
    }
    

提交回复
热议问题