Hi
I am experimenting with declarative scripts and have this simple script:
pipeline {
agent { label "mypc" }
stages {
stage('build') {
steps {
sh 'python --version'
}
}
}
post {
success {
script: emailext (subject: "STARTED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
body: """<p>STARTED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
<p>Check console output at "<a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>"</p>""",
recipientProviders: [$class: 'DevelopersRecipientProvider']])
}
}
}
I can’t specify the list of default recipients in the global settings for the email-ext plugin, as the required recipients change from project to project. I need to specify the list in the script. I’ve received a suggestion to:
“use this pipeline step https://jenkins.io/doc/pipeline/steps/email-ext/#emailextrecipients-extended-email-recipients to get the recipients and then use the "to" parameter to the emailext step and add your own addresses to the return of that step”
I don’t know how to do this. Please could someone show me how to modify my script to do it?
Best regards
David
--
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/21c2aac48caa41998f52a2e233d4ed76%40EUX13SRV1.EU.NEC.COM.
For more options, visit https://groups.google.com/d/optout.
Hi Danny,
That worked (with email addresses in quotes) – thanks.
Do you know how I would specify ‘to:’ as a certain email address + committers?
Best regards
David
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAObRFCX0ZaN4MPqiNy9tB8z0nr_g1zFrZ1Ssa24Bhb997G7p4A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Click here to report this email as spam.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/1ba2614920ab4f01a957692fe395146e%40EUX13SRV1.EU.NEC.COM.
Hi Slide
Thanks. I tried the code below based on your suggestion but the syntax of my change isn’t quite right. Can you help please?
post {
success {
script{ def recipients = emailextrecipients([ [$class: 'DevelopersRecipientProvider'] ])
emailext (to: "daldrich"; recipients,
subject: '${DEFAULT_SUBJECT}',
body: '${DEFAULT_CONTENT}',
recipientProviders: [[$class: 'DevelopersRecipientProvider']])
}
}
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 13: expecting ')', found ',' @ line 13, column 57.
xt (to: "daldrich"; recipients,
^
1 error
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVetEq5qDryWrRDS85Xg2uTtcFtbeo1sn97F15DD%3DPM7ZA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/0469c2cb3fe64a4ab024f74c10d4b214%40EUX13SRV1.EU.NEC.COM.
Thanks Slide
David
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVe-KveLCY%2BcJDM3C-eb8ZwqtUaAhjBd_T4wZ2Sakiwo9g%40mail.gmail.com.
Hi Slide
I think the script is still not quite right. I now have:
post {
success {
script{ def recipients = emailextrecipients([ [$class: 'DevelopersRecipientProvider'] ])
emailext (to: "daldrich," + recipients,
subject: '${DEFAULT_SUBJECT}',
body: '${DEFAULT_CONTENT}',
recipientProviders: [[$class: 'DevelopersRecipientProvider']])
}
}
}
I see two problems:
1) The output shows:
Failed to create e-mail address for co...@us.COM co...@us.COM co...@us.COM
Sending email to: co...@us.COM co...@us.COM co...@us.COM
These are the correct committers’ email addresses but I have disguised them for this question. I receive an email but I don’t know why I see the ‘Failed’ message in the log. Any ideas please?
2) The subject uses : '${DEFAULT_SUBJECT}', which ends with ‘$BUILD_STATUS!’ In the received email the build status was ‘Building!’. This is in ‘post’ so I expect the status to be ‘Success!’. Any idea why this is wrong?
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/1b7a1ef389fa4e48bbf39dce8f8f8550%40EUX13SRV1.EU.NEC.COM.
I tried replacing my code with that produced by the snippet generator:
script{ emailext (body: '${DEFAULT_CONTENT}',
recipientProviders: [[$class: 'CulpritsRecipientProvider']],
subject: '${DEFAULT_SUBJECT}',
to: 'daldrich')
}
But the result is an email to daldrich but not to the culprits.
Could this be a bug in the emailext plugin?
BR
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/28f1e4b702d3473daea012b34b77b861%40EUX13SRV1.EU.NEC.COM.
Try removing the recipientProvider parameter to emailext, I'm not sure if that will mess things up. I'm not familiar with declarative pipeline enough to say how to get the correct build status. How are you running the job? If you are running it manually and there have been no changes, then there are no culprits. The culprits are pulled from the changes from the scm you specify.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/4b69f78cd1054bd084bfd6371bebf993%40EUX13SRV1.EU.NEC.COM.
Hi Slide
I am running the job manually. There are commits by another user since the job last ran, so I assume there should be culprits. The job actually succeeds, but I’m assuming that the culprits should still receive the email.
If I remove:
recipientProviders: [[$class: 'CulpritsRecipientProvider']],
then the culprits definitely won’t get the email?
BR
David
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVfn_ApYwkOuM_qPVoZzucgTd71GF1HRcU5A5_P68Gui3A%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/2ba974eb543740449ab216628ee15bdf%40EUX13SRV1.EU.NEC.COM.
Hi Slide
Thanks for helping me with this. I am using a declarative pipeline. In the ‘post’ clause, I set ‘success’, ‘failure’, ‘unstable’ and ‘changed’ to all be:
script{ emailext (body: '${DEFAULT_CONTENT}',
recipientProviders: [[$class: 'CulpritsRecipientProvider']],
subject: '${DEFAULT_SUBJECT}',
to: 'daldrich')
‘Failure’ works fine – daldrich and the culprits are emailed.
However, when the failure is fixed, i.e. we have condition ‘changed’, only daldrich is emailed. In a traditional job the culprits should also be notified of the change to Fixed.
Perhaps this is an email-ext plugin bug?
Best regards
David
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVd4%3Dem9nYxTdM0KivftXZr66ix89Wv-1VB-q8-TrSJ2Nw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/4b79cb83d3b74f879f8ed762fce88f16%40EUX13SRV1.EU.NEC.COM.
Well I haven’t found definitions of the providers so I can’t be sure, but the free-style job specifies:
Fixed: Recipient List, Culprits
and the Project Recipient List contains daldrich
So, yes, I think they are equivalent.
BR
David
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVcab9VL_7JONVO2osdsvXSmUc9Xva5%2B41ZPeaz5Pg_wkQ%40mail.gmail.com.
Then it's possible that it's the way culprits are determined for each job type. Free style inherits from AbstractProject, so the build has a getCulprits() that email-ext can call. It has to determine culprits on its own for pipeline jobs and it may not have all the info that a free style project does.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/3c535b8324664d338cab565b1c22ffc4%40EUX13SRV1.EU.NEC.COM.
Hi Slide
Do you know whether it’s possible to get the culprits without using email-ext, i.e. using the ‘mail’ command?
Best regards
David
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVfXnC%3DQnMZcLjRz5YTSk3qmRn8qP1niaKyuNR0e%3D8zXeQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/c2341e79d3074e1586de3d52eb9822a8%40EUX13SRV1.EU.NEC.COM.