Fix build description permission error.
Impersonate the system user while setting build description because the gearman plugin runs outside of a user context. Change-Id: Ib8a0eacd44c067a22e6c5afc7a0984a247792f1e
This commit is contained in:
parent
61e47a1e8b
commit
2f579179bb
|
@ -20,11 +20,14 @@
|
|||
package hudson.plugins.gearman;
|
||||
|
||||
import hudson.model.Run;
|
||||
import hudson.security.ACL;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.acegisecurity.context.SecurityContextHolder;
|
||||
import org.acegisecurity.context.SecurityContext;
|
||||
import org.gearman.client.GearmanJobResult;
|
||||
import org.gearman.client.GearmanJobResultImpl;
|
||||
import org.gearman.worker.AbstractGearmanFunction;
|
||||
|
@ -81,11 +84,16 @@ public class SetDescriptionWorker extends AbstractGearmanFunction {
|
|||
// find build then update its description
|
||||
Run<?,?> build = GearmanPluginUtil.findBuild(jobName, Integer.parseInt(buildNumber));
|
||||
if (build != null) {
|
||||
SecurityContext oldContext = ACL.impersonate(ACL.SYSTEM);
|
||||
try {
|
||||
build.setDescription(buildDescription);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalArgumentException("Unable to set description for " +
|
||||
jobName + ": " + buildNumber);
|
||||
try {
|
||||
build.setDescription(buildDescription);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalArgumentException("Unable to set description for " +
|
||||
jobName + ": " + buildNumber);
|
||||
}
|
||||
} finally {
|
||||
SecurityContextHolder.setContext(oldContext);
|
||||
}
|
||||
jobResultMsg = "Description for Jenkins build " +buildNumber+" was updated to " + buildDescription;
|
||||
jobResult = true;
|
||||
|
|
Loading…
Reference in New Issue