Skip to content

Commit

Permalink
[FIX JENKINS-38615] Add user to restart log message
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-beck committed Oct 4, 2016
1 parent 96ec7a2 commit 4462eda
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion core/src/main/java/hudson/model/UpdateCenter.java
Expand Up @@ -30,6 +30,7 @@
import hudson.PluginManager;
import hudson.PluginWrapper;
import hudson.ProxyConfiguration;
import hudson.security.ACLContext;
import jenkins.util.SystemProperties;
import hudson.Util;
import hudson.XmlFile;
Expand Down Expand Up @@ -1371,6 +1372,11 @@ public class RestartJenkinsJob extends UpdateCenterJob {
@Exported(inline=true)
public volatile RestartJenkinsJobStatus status = new Pending();

/**
* The name of the user that started this job
*/
private String authentication;

/**
* Cancel job
*/
Expand All @@ -1384,6 +1390,7 @@ public synchronized boolean cancel() {

public RestartJenkinsJob(UpdateSite site) {
super(site);
this.authentication = Jenkins.getAuthentication().getName();
}

public synchronized void run() {
Expand All @@ -1392,7 +1399,10 @@ public synchronized void run() {
}
status = new Running();
try {
Jenkins.getInstance().safeRestart();
// safeRestart records the current authentication for the log, so set it to the managing user
try (ACLContext _ = ACL.as(User.get(authentication, false, Collections.emptyMap()))) {
Jenkins.getInstance().safeRestart();
}
} catch (RestartNotSupportedException exception) {
// ignore if restart is not allowed
status = new Failure();
Expand Down

0 comments on commit 4462eda

Please sign in to comment.