Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set GitHub push user as BUILD_USER_ID #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import hudson.triggers.SCMTrigger;
import hudson.triggers.SCMTrigger.SCMTriggerCause;

import java.lang.reflect.Field;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.builduser.utils.UsernameUtils;
import org.jenkinsci.plugins.builduser.varsetter.IUsernameSettable;

Expand All @@ -18,6 +20,18 @@ public boolean setJenkinsUserBuildVars(SCMTriggerCause cause,
if (cause != null) {
UsernameUtils.setUsernameVars("SCMTrigger", variables);

// sets pushedBy provided by GitHubPushCause as BUILD_USER_ID
try {
Field pushedByField = cause.getClass().getDeclaredField("pushedBy");
pushedByField.setAccessible(true);
String pushedBy = (String) pushedByField.get(cause);
if (StringUtils.isNotEmpty(pushedBy)) {
variables.put(BUILD_USER_ID, pushedBy);
}
} catch (ReflectiveOperationException exception) {
// do nothing
}

return true;
} else {
return false;
Expand Down