Almost there but still not perfect yet: node { try { // some stages for the workflow }
catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e){ echo "the job was cancelled or aborted" } catch (err){ > stage 'Send Notification' > def msgimg="https://localhost/images/some.gif" > def newurl="${env.BUILD_URL}console" > mail (to: 'adminj...@somename.com', > subject: "Job '${env.JOB_NAME}' (${env.BUILD_NUMBER}) has had an error.", > body: "Ran on <b>${env.NODE_NAME}</b><br>job failed <a href=${newurl}>${env.JOB_NAME}</a>. Some more message.... .<br><img src=${msgimg} />", > mimeType:'text/html'); > currentBuild.result = 'FAILURE' > } } I can get the catch the interrupted job and it echos the string. But for any other exceptions i was expecting it will be caught by the other. But it doesn't. On Wednesday, February 3, 2016 at 1:39:43 PM UTC-6, Meiteimacha999 wrote: > > okay - so when a job fails, it throws the exception: hudson.AbortException: > script returned exit code 1 > And when its cancelled by the new job, it throws this: > org.jenkinsci.plugins.workflow.steps.FlowInterruptedException > > I am not a groovy man, so any help to put a condition inside the catch > (like an IF statement) will be helpfull > > > > > > > On Wednesday, February 3, 2016 at 11:17:21 AM UTC-6, Meiteimacha999 wrote: >> >> how do i check the difference? is there a way to print it in Windows? >> >> On Wednesday, February 3, 2016 at 10:58:40 AM UTC-6, Daniel Beck wrote: >>> >>> Have you tried looking more closely at the exception 'err' to see >>> whether they're different based on how the build was failed/aborted? >>> >>> On 03.02.2016, at 17:50, Meiteimacha999 <nirish...@gmail.com> wrote: >>> >>> > i have my workflow set up like so. This sends an email notification >>> when a job fails. >>> > >>> > >>> > >>> > >>> > node("slave1") { >>> > ws("e:\\jenkins\\workspace\\jobname\\${env.BUILD_NUMBER}") { >>> > try{ >>> > stage name: 'sync', concurrency: 2 >>> > bat '''echo "before sync" >>> > set a=%RANDOM% >>> > echo %a% >>> > echo "after sync"''' >>> > sleep 10 >>> > >>> > stage name: 'build', concurrency: 1 >>> > bat '''mkdir %cd%\\Build-%BUILD_NUMBER% >>> > dir %cd% >>> > cd %cd%\\Build-%BUILD_NUMBER% >>> > copy /y NUL EmptyFile.txt >NUL''' >>> > sleep 10 >>> > >>> > stage name: 'test', concurrency: 2 >>> > bat '''dir %cd% >>> > dir %cd%\\Build-%BUILD_NUMBER%''' >>> > sleep 17 >>> > } >>> > >>> > catch (err){ >>> > stage 'Send Notification' >>> > def msgimg="https://localhost/images/some.gif" >>> > def newurl="${env.BUILD_URL}console" >>> > mail (to: 'adminj...@somename.com', >>> > subject: "Job '${env.JOB_NAME}' (${env.BUILD_NUMBER}) has >>> had an error.", >>> > body: "Ran on <b>${env.NODE_NAME}</b><br>job failed <a >>> href=${newurl}>${env.JOB_NAME}</a>. Some more message.... .<br><img >>> src=${msgimg} />", >>> > mimeType:'text/html'); >>> > currentBuild.result = 'FAILURE' >>> > } >>> > >>> > } >>> > } >>> > >>> > >>> > But the issue, is i am also getting email notice for jobs that were >>> cancelled due to the newer job catching up with the older job while running >>> concurrently. I just want email notice for jobs that actually failed due to >>> some error and not be notified for jobs that were marked failed as they >>> were canceled by a presiding job. >>> > Have anyone handled this issue? >>> > >>> > >>> > >>> > >>> > >>> > >>> > >>> > >>> > >>> > -- >>> > You received this message because you are subscribed to the Google >>> Groups "Jenkins Users" group. >>> > To unsubscribe from this group and stop receiving emails from it, send >>> an email to jenkinsci-use...@googlegroups.com. >>> > To view this discussion on the web visit >>> https://groups.google.com/d/msgid/jenkinsci-users/dc1ef652-5f53-44a0-94d3-4ae0626b0dfc%40googlegroups.com. >>> >>> >>> > For more options, visit https://groups.google.com/d/optout. >>> >>> -- You received this message because you are subscribed to the Google Groups "Jenkins Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/95a1c321-4e36-4188-afd6-16f7181f7f4c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.