Skip to content
Permalink
Browse files
[DONE JENKINS-20877] install plugins if required
  • Loading branch information
escoem committed May 29, 2018
1 parent 799cb60 commit 2173d0b6f01d859fb3f9cbb8747aa3db915357f3
@@ -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;
@@ -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);
}
}
}
@@ -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);
@@ -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) {
@@ -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();
@@ -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>

0 comments on commit 2173d0b

Please sign in to comment.