Send email on jenkins pipeline failure

前端 未结 6 1540
不知归路
不知归路 2021-01-30 17:16

How can i add to a jenkins pipeline an old-style post-build task which sends email when the build fails? I cannot find \"Post-build actions\" in the GUI for a pipeline. I know t

6条回答
  •  甜味超标
    2021-01-30 17:59

    This answer worked on my Jenkins ver. 2.96.

    Jenkins pipeline email not sent on build failure - Stack Overflow

     pipeline {  
         agent any  
         stages {  
             stage('Test') {  
                 steps {  
                     sh 'echo "Fail!"; exit 1'  
                 }  
             }  
         }  
         post {  
             always {  
                 echo 'This will always run'  
             }  
             success {  
                 echo 'This will run only if successful'  
             }  
             failure {  
                 mail bcc: '', body: "Example
    Project: ${env.JOB_NAME}
    Build Number: ${env.BUILD_NUMBER}
    URL de build: ${env.BUILD_URL}", cc: '', charset: 'UTF-8', from: '', mimeType: 'text/html', replyTo: '', subject: "ERROR CI: Project name -> ${env.JOB_NAME}", to: "foo@foomail.com"; } unstable { echo 'This will run only if the run was marked as unstable' } changed { echo 'This will run only if the state of the Pipeline has changed' echo 'For example, if the Pipeline was previously failing but is now successful' } } }

提交回复
热议问题