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

后端 未结 3 1173
长情又很酷
长情又很酷 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 14:05

    What I did to include useful information in my mail about the failure:

    try {
        stage 'checkout cvs'
        node('master') {
            /** CODE **/
        }
    
        stage 'compile'
        node('master') {
            /** CODE **/
        }
    
        stage 'test unit'
        node('master') {
            /** CODE **/
        }   
    
        stage 'package'
        node('master') {
            /** CODE **/
        }
    
        stage 'nexus publish'
        node('master') {
            /** CODE **/
        }
    
        stage 'Deploy to App Server'
        node('master') {
            /** CODE **/            
        }
    
    } catch(e) {
        String error = "${e}";
        // Make the string with job info, example:
        // ${env.JOB_NAME}
        // ${env.BUILD_NUMBER} 
        // ${env.BUILD_URL}
        // and other variables in the code
        mail bcc: '',
             cc: '',
             charset: 'UTF-8',
             from: '',
             mimeType: 'text/html',
             replyTo: '',
             subject: "ERROR CI: Project name -> ${env.JOB_NAME}",
             to: "${mails_to_notify}",
             body: "${pivote}
    \n\nMensaje de error: ${error}\n\n
    Projecto: ${env.JOB_NAME}
    Build Number: ${env.BUILD_NUMBER}
    URL de build: ${env.BUILD_URL}"; error "${error}" }

提交回复
热议问题