2
votes

I have created a test workflow as below:

node("master") {
ws("/opt/mount1/jenkins/jobs/GoogleFlow/workspace/${env.BUILD_NUMBER}") {
try {
stage name: 'sync', concurrency: 3
  echo "before sync"
  sh '''touch buildFile
  echo "This is from ${BUILD_NUMBER}" >> buildFile
  cat buildFile'''
  sh "sleep 5"
  echo "after sync"
  sh "date"


stage name: 'build', concurrency: 1
  echo "before build"
  sh "date"
  sh '''sleep 10
  cat buildFile'''
  echo "build 1/3"
  sh "sleep 5"
  echo "build 2/3"
  sh '''sleep 5
  cat buildFile'''
  echo "build 3/3"
  sh "date"

stage name: 'test', concurrency: 3
  echo "before test"
  sh "date"
  sh '''sleep 10
  cat buildFile'''
  sh "date"

 stage name: 'delete', concurrency: 1
 sh '''pwd
 ls -al'''
 //deleteDir()
 //sh '''pwd
 //ls -al'''

}

 catch (err){
    stage 'Send Notification'
        mail (to: '[email protected]',
         subject: "test",
         body: "test");
    }
}
}

I am trying to get an email notification using the try-catch. I have referred this blog post, but when it comes to stage to 'send notification' it just sits there hung.

But if i use the old Jenkins job way, i can receive emails. This shows that the SMTP setup is working. Below is the console output, when it hungs

[Pipeline] Allocate node : Start
Running on master in /opt/mount1/jenkins/jobs/GoogleFlow/workspace@4
[Pipeline] node {
[Pipeline] Allocate workspace : Start
Running in /opt/mount1/jenkins/jobs/GoogleFlow/workspace/205
[Pipeline] ws {
[Pipeline] stage: sync
Entering stage sync
Proceeding
[Pipeline] echo
before sync
[Pipeline] sh
[205] Running shell script
+ touch buildFile
+ echo 'This is from 205'
+ cat buildFile
This is from 205
[Pipeline] sh
[205] Running shell script
+ sleep 5
[Pipeline] echo
after sync
[Pipeline] sh
[205] Running shell script
+ date
Tue Feb  2 22:54:52 UTC 2016
[Pipeline] stage: build
Entering stage build
Waiting for builds [204]
Canceled since #206 got here
[Pipeline] stage: Send Notification
Entering stage Send Notification
Proceeding
[Pipeline] mail

Any idea on how to fix?

Jenkins - 1.643 Mailer plugin - 1.11

1
Did you try to re-throw the exception after the mail step?amuniz
This feels like a strange workaround. In general I found no easy way yet to specify actions to do upon failure, maybe exception catching is the thing?giorgiosironi

1 Answers

0
votes

I had the same problem and fixed it by upgrading mailer to v 1.16.