Get build requestor using Groovy script (Jenkins / email-ext) -
i want username and/or email address of build requestor in post-build script.
sidenote: want requestor can set email sender of post-build email notification dynamically in email-ext plugin's pre-send script.
abstractbuild has built-in support abstractbuild.getculprits() , abstractbuild.hasparticipant(user user) can't find method retrieving requestor. can't find useful reference in reference list user class either.
i managed solve via cause of the build, recommended in answer.
the reason build requestor can found in cause build makes perfect sense when think it: not every build directly triggered user. if triggered user, list of causes build contains cause.useridcause, user's id , name.
this code snippet worked me. extracts username build via cause , sets , replyto headers. use in pre-send script of email-ext jenkins plugin.
import javax.mail.internet.internetaddress cause = build.getcause(hudson.model.cause.useridcause.class); username = cause.getusername() id = cause.getuserid() email = new internetaddress(string.format("%s <%s@example.com>", username, id)) msg.setfrom(email) msg.setreplyto(email);
Comments
Post a Comment