Skip to content
Permalink
Browse files
Merge pull request #18 from MCardenasBlanco/JENKINS-45195
FIXED JENKINS-45195 Import job fails when user lacks overall / administer
  • Loading branch information
escoem committed Jul 11, 2017
2 parents 4c92f32 + 5dcd939 commit 447e1a3c662b473110770994426afe07759efee2
@@ -30,6 +30,7 @@
import hudson.model.Descriptor;
import hudson.model.RootAction;
import hudson.model.TopLevelItem;
import hudson.security.AccessDeniedException2;
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;
import jenkins.model.Jenkins;
@@ -130,7 +131,16 @@ private void doImportInternal(String jobUrl) throws IOException {
doImportInternal(childJob.getUrl());
}
}
Jenkins.getActiveInstance().doReload();

try{
Jenkins instance= Jenkins.getActiveInstance();
instance.checkPermission(instance.ADMINISTER);
Jenkins.getActiveInstance().doReload();
} catch(AccessDeniedException2 ex2){
remoteJobsImportStatus.get(remoteJob).setStatus(MessagesUtils.formatSuccessNotReloaded());
LOG.log(Level.INFO, "Failed to reload Jenkins config because the user lacks the Overall Administer permission");

}
}

catch (final Exception e) {
@@ -46,7 +46,9 @@ public static String formatFailedException(final String message) {
public static String formatSuccess() {
return Messages.Job_Import_Plugin_Import_Success();
}

public static String formatSuccessNotReloaded() {
return Messages.Job_Import_Plugin_Import_Success_NotReloaded();
}
/**
* Static-only access.
*/
@@ -25,5 +25,6 @@
DisplayName = Job Import Plugin

Job.Import.Plugin.Import.Success = SUCCESS
Job.Import.Plugin.Import.Success.NotReloaded = SUCCESS - Reload was not performed due to lack of Overall/Administer permissions.
Job.Import.Plugin.Import.Failed.Duplicate = FAILED - Duplicate Job Name
Job.Import.Plugin.Import.Failed.Exception = FAILED - {0}

0 comments on commit 447e1a3

Please sign in to comment.