Skip to content

Commit

Permalink
[DONE JENKINS-20877] install plugins if required
Browse files Browse the repository at this point in the history
  • Loading branch information
escoem committed May 29, 2018
1 parent 799cb60 commit 2173d0b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Expand Up @@ -30,6 +30,7 @@
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
import com.cloudbees.plugins.credentials.domains.DomainRequirement;
import hudson.Extension;
import hudson.PluginManager;
import hudson.model.Describable;
import hudson.model.Descriptor;
import hudson.model.Item;
Expand Down Expand Up @@ -123,7 +124,7 @@ public void doImport(final StaplerRequest request, final StaplerResponse respons
if (remoteJobsAvailable != null && remoteJobsAvailable.equalsIgnoreCase("true")) {
if (request.hasParameter(Constants.JOB_URL_PARAM)) {
for (final String jobUrl : Arrays.asList(request.getParameterValues(Constants.JOB_URL_PARAM))) {
doImportInternal(jobUrl, localFolder, credentialId, remoteJobs, remoteJobsImportStatus);
doImportInternal(jobUrl, localFolder, credentialId, shouldInstallPlugins(request.getParameter("plugins")), remoteJobs, remoteJobsImportStatus);
}
}
}
Expand Down Expand Up @@ -171,6 +172,7 @@ public void doQuery(final StaplerRequest request, final StaplerResponse response

private void doImportInternal(String jobUrl, String localPath,
String credentialId,
boolean installPlugins,
SortedSet<RemoteItem> remoteJobs,
SortedMap<RemoteItem, RemoteItemImportStatus> remoteJobsImportStatus) throws IOException {
final RemoteItem remoteJob = RemoteItemUtils.getRemoteJob(remoteJobs, jobUrl);
Expand Down Expand Up @@ -203,14 +205,21 @@ private void doImportInternal(String jobUrl, String localPath,
}

if (newItem != null) {

if (installPlugins ) {
Jenkins instance = Jenkins.get();
instance.getAuthorizationStrategy().getACL(instance).checkPermission(Jenkins.ADMINISTER);
PluginManager.createDefault(Jenkins.get()).prevalidateConfig(inputStream);
}

newItem.save();
}

remoteJobsImportStatus.get(remoteJob).setStatus(MessagesUtils.formatSuccess());

if (remoteJob.isFolder() && ((RemoteFolder)remoteJob).hasChildren()) {
for (RemoteItem childJob : ((RemoteFolder)remoteJob).getChildren()) {
doImportInternal(childJob.getUrl(), newItem.getFullName(), credentialId, remoteJobs, remoteJobsImportStatus);
doImportInternal(childJob.getUrl(), newItem.getFullName(), credentialId, installPlugins, remoteJobs, remoteJobsImportStatus);
}
}
} catch (final Exception e) {
Expand Down Expand Up @@ -243,6 +252,9 @@ private void doQueryInternal(RemoteFolder parent, String url, NullSafeCredential
private boolean isRecursive(String param) {
return StringUtils.equals("on", param);
}
private boolean shouldInstallPlugins(String param) {
return StringUtils.equals("on", param);
}

public String getRootUrl() {
return Jenkins.get().getRootUrl();
Expand Down
Expand Up @@ -64,6 +64,11 @@
<f:entry title="${%Job.Import.Plugin.Import.Section.LocalFolder.Title}" field="localFolder">
<f:textbox name="localFolder" field="localFolder" value="${it.localFolder}"/>
</f:entry>
<j:if test="${h.hasPermission(app.ADMINISTER)}">
<f:entry title="${%Install required plugins}" field="plugins">
<f:checkbox name="plugins" value="${plugins}" default="false"/>
</f:entry>
</j:if>
<table class="jobImportPlugin" cellpadding="3" cellspacing="3">
<tr>
<th>Import?</th>
Expand Down

0 comments on commit 2173d0b

Please sign in to comment.