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

JENKINS-45195 Import job fails when user lacks overall / administer #18

Merged
merged 3 commits into from
Jul 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}