3

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?

TruckerCat
  • 1,437
  • 2
  • 16
  • 39
  • In the `getTeamRecipients` function, you are writing your own code to return names. why? Have a look at [this](https://stackoverflow.com/a/30229747/5003256) instead. – SV Madhava Reddy Mar 29 '18 at 07:24
  • And as per the official `Email Ext Plugin`, versions below `2.57` will not send emails to outside because of security. So please update your plugin if needed. [Check here - 2.57.1 (March 20, 2017)](https://wiki.jenkins.io/display/JENKINS/Email-ext+plugin). – SV Madhava Reddy Mar 29 '18 at 07:26

0 Answers0