I am currently trying to understand why Jenkins is not sending emails. The expected behavior is, that Jenkins will send emails to the whole team if the master branch is broken. If a feature branch breaks a email to the person who broke it, should be send.
Emails for the master branch are working, but not for broken feature branches.We are using the email-ext plugin. If you take a look at the code below you will see that the getEMailRecipients
function will return an empty string for feature branches.
Docs example
In the docs an example is given that should
Send an email to abc plus any addresses returned by the providers
emailext (
body: 'A Test EMail',
recipientProviders: [
[$class: 'DevelopersRecipientProvider'],
[$class: 'RequesterRecipientProvider']
],
subject: 'Test',
to: 'abc'
)
My understanding of this example is, that an email should be send even if the to
property is empty.
Property value docs
The docs for the plugin state the following for the 'CulpritsRecipientProvider'
option
Sends email to the list of users who committed a change since the last non-broken build till now. This list at least always include people who made changes in this build, but if the previous build was a failure it also includes the culprit list from there.
My Code
Helper functions:
def getTeamRecipients() {
return 'name1 name2 nameX'
}
def getEMailRecipients(currentBranch) {
return (currentBranch.toLowerCase().contains("current") ||
currentBranch.toLowerCase().contains("master")) ?
getTeamRecipients() :
""
}
def sendEMail(recipients) {
emailext (
to: recipients,
subject: "Job '${env.JOB_NAME}' is in state ${currentBuild.currentResult}",
body: "See ${env.BUILD_URL} for more details",
recipientProviders: [
[$class: 'CulpritsRecipientProvider'],
]
)
}
Email Send part:
if (currentBuild.currentResult == "FAILURE") {
def recipients = getEMailRecipients("$BRANCH_NAME")
sendEMail(recipients)
}
Does anyone have an idea what is wrong with my build script code?