简体   繁体   中英

Jenkins - How do I pass Email-ext plugin's “Culprits” email list variable to a build step?

Culprits is the list of users who committed a change since the last non-broken build till now. The Jenkins Email-ext plugin is able to send an email to the culprits during a Post-Build action.

I want to use the list of emails defined by Culprits in a python script build step inside of my Jenkins job.

Can anyone suggest how I can do this?

The 'culprits' list comes from the SCM plugin in jenkins and includes all users who have committed since the last successful build. Ultimately the email-ext plugin is sourcing its list from scm and generating the email addresses based on the following heuristic

The plugin will generate an email address based on the committer's id and an appended "default email suffix" from Jenkins's global configuration page. For instance, if a change was committed by someone with an id "first.last", and the default email suffix is "@somewhere.com", then an email will be sent to "first.last@somewhere.com"

If your email addresses have some sort of pattern (and they must do, otherwise the email-ext plugin would not be generating the correct addresses) then you can generate them yourself inside a groovy script eg:

import hudson.model.*
def culprits = build.getCulprits()
def list = culprits.collect{it.getFullName().toLowerCase().replace(" ", ".") + "@mydomain.com"}

This example would convert a culprit like "Adam Smith" to adam.smith@mydomain.com But you could replace the call to getFullName() with a call to getId() and manipulate that however appropriate. eg:

def list = culprits.collect{it.getId().toLowerCase() + "@mydomain.com"}

Which is the basic format that email-ext uses - You can get a full list of user properties from the documentation.

Now you have the list in a groovy script, but how to make that list available to your python script? That will come down to what you are used to doing. You could write the list to your workspace and read it from python, or save the result to an environmental variable, or even save it to a build parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM