Answers: <p>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:</p>
  <pre><code>#!/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: 'x@sample.com'
          }  
      } 
  }
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2024-09-15T17:33:49.553Z
Answers: 2024-09-29T23:01:42.987Z
Answers: 2024-09-29T23:01:42.987Z
Answers: YassineLbk
Body: <p>In Jenkins pipeline I have (using <strong>Extended Email</strong> plugin):</p>
  <pre><code>#!/usr/bin/env groovy
  
  pipeline {
  
      agent any
  
      stages {
          stage('install') {
              steps {
                  echo 'install...'
              }
          }
      }
  
      post {  
          failure {  
              emailext body: 'fail', subject: 'failed', to: 'x@sample.com'
          }  
          // always {}
      } 
  }
  </code></pre>
  <p>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 <code>always {}</code> line above, you get:</p>
  <pre><code>org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
  WorkflowScript: 69: No steps specified for branch @ line 69, column 17.
              always {  
                     ^
  </code></pre>
  <p>however, that build fails silently (bcz syntax issue). How to get emails on such cases too?</p>
  
Tags: <jenkins><jenkins-pipeline><jenkins-plugins><jenkinsfile>
Title: How set Jenkins to send email when Pipeline is broken
UserDisplayName: T.Todua
ThreadText: # How set Jenkins to send email when Pipeline is broken
  
  (Asked by: username_0 on 2024-09-14)
  
  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: 'x@sample.com'
          }  
          // 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?
  
  **Tags:** jenkins, jenkins-pipeline, jenkins-plugins, jenkinsfile
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-09-15. Score: 1 | Accepted answer
  
  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: 'x@sample.com'
          }  
      } 
  }
  
  ```
  
  
  ---
  
  