0

In Jenkins pipeline I have (using Extended Email plugin):

#!/usr/bin/env groovy

pipeline {

    agent any

    stages {
        stage('install') {
            steps {
                echo 'install...'
            }
        }
    }

    post {  
        failure {  
            emailext body: 'fail', subject: 'failed', to: '[email protected]'
        }  
        // always {}
    } 
}

When build fails it sends email. However, I want to send email also, when the pipeline syntax is broken itself, eg. if you uncomment the always {} line above, you get:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 69: No steps specified for branch @ line 69, column 17.
            always {  
                   ^

however, that build fails silently (bcz syntax issue). How to get emails on such cases too?

1 Answer 1

1

You can't do that if your post stages syntax is incorrect. But, if the body pipeline has an error and the post stage is error-free, it sends the email. For example, this works:

#!/usr/bin/env groovy

pipeline {

    agent any

    stages {
        stage('install') {
            steps {
                eeecho_this_is_a_typo 'install...'
            }
        }
    }

    post {  
        failure {  
            emailext body: 'fail', subject: 'failed', to: '[email protected]'
        }  
    } 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.