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

旧巷老猫 提交于 2019-12-05 10:00:42

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/30225536/jenkins-how-do-i-pass-email-ext-plugins-culprits-email-list-variable-to-a-b

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!