Using mailer publisher inside Jenkinsfile

363 views
Skip to first unread message

Raffaele Sgarro

unread,
Jan 9, 2017, 7:44:24 AM1/9/17
to jenkins...@googlegroups.com
I have this Jenkinsfile in my repository, which is fed to Jenkins via a Multibranch pipeline job:
node {
checkout scm

stage("Compile") {
sh "./gradlew classes"
}

stage("Test") {
try {
sh "./gradlew cleanTest test"
} finally {
junit "**/build/test-results/test/TEST-*.xml"
}
}
}
I need to be notified when build fails or is back to normal. I found the publishers/mailer in the DSL documentation but it doesn't inside node {}, neither in the top-level scope:

publishers {
    mailer('m...@example.com', true, true)
}

Lots of examples use catchErrors {} or a plain try {} finally {} and maintain the build status by hand. Is any declarative approach like publisher/mail available for my setup? I would also get rid of that try {} finally {} for junit test results processing since there is a junit publisher.

Ohad Cohen

unread,
Jan 9, 2017, 10:13:00 AM1/9/17
to Jenkins Users
Hi Raffaele,

If you are using the 'Declarative Pipleine' syntax and you want to use 'Job Dsl' features, I think you should do:

jobDsl scriptText: '''publishers {
    mailer(\'m...@example.com\', true, true)
}'''

** Taken from the snippet generator

hope this was helpful

בתאריך יום שני, 9 בינואר 2017 בשעה 14:44:24 UTC+2, מאת Raffaele Sgarro:

Raffaele Sgarro

unread,
Jan 9, 2017, 6:36:18 PM1/9/17
to Jenkins Users
Hi Ohad! As I understand from your kind message, the job DSL is not available in a Jenkinsfile. The jobDsl trick is clearly a hack and I prefer keeping it simple, even if try-finally and if-else constructs don't really belong to a declarative way of describing a pipeline.

May I ask if you think this (configuring the mailer publisher via stage([$class: 'Mailer'])) is intended or just not implemented yet?

Slide

unread,
Jan 9, 2017, 6:53:42 PM1/9/17
to Jenkins Users
For pipeline you have two options:



The first uses the bundled Mailer plugin, the second uses Email-ext, which allows for more options.

On Mon, Jan 9, 2017 at 4:36 PM Raffaele Sgarro <raffael...@gmail.com> wrote:
Hi Ohad! As I understand from your kind message, the job DSL is not available in a Jenkinsfile. The jobDsl trick is clearly a hack and I prefer keeping it simple, even if try-finally and if-else constructs don't really belong to a declarative way of describing a pipeline.

May I ask if you think this (configuring the mailer publisher via stage([$class: 'Mailer'])) is intended or just not implemented yet?

--
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/58191228-334c-45e0-84eb-f602a2105792%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Raffaele Sgarro

unread,
Jan 9, 2017, 7:08:55 PM1/9/17
to Jenkins Users

The problem is that both Mailer and Email-ext require wrapping steps inside a try/catch or equivalent. I already use Mailer activated by the catchError trigger, but hoped to find a declarative solution because loops and branches are too scripty for a Jenkinsfile in my opinion (I don't want, should not need and definitely don't know how to test pipeline files).

However this is how things work and I guess there must be valid reasons for it. Thanks for your support!


You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/VWnkOYPOKTA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVeMFGbn-NYmS_%3DSzTa7mV8bZCRVoVDeextBMWLFV7ih%2Bw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages