Skip to content
Permalink
Browse files

Merge pull request #3201 from dwnusbaum/JENKINS-48604

[JENKINS-48604] Do not downgrade plugins that are dependencies of detached plugins when upgrading Jenkins
  • Loading branch information...
daniel-beck committed Dec 19, 2017
2 parents c32b6d8 + 6632aef commit 1dc2c6d5ff666d60a0eb54125ce7694986d1025b
@@ -650,7 +650,17 @@ protected static void addDependencies(URL hpiResUrl, String fromPath, Set<URL> d
continue;
}

String artifactId = dependencyToken.split(":")[0];
String[] artifactIdVersionPair = dependencyToken.split(":");
String artifactId = artifactIdVersionPair[0];
VersionNumber dependencyVersion = new VersionNumber(artifactIdVersionPair[1]);

PluginManager manager = Jenkins.getActiveInstance().getPluginManager();
VersionNumber installedVersion = manager.getPluginVersion(manager.rootDir, artifactId);
if (installedVersion != null && !installedVersion.isOlderThan(dependencyVersion)) {
// Do not downgrade dependencies that are already installed.
continue;
}

URL dependencyURL = context.getResource(fromPath + "/" + artifactId + ".hpi");

if (dependencyURL == null) {
@@ -26,6 +26,7 @@

import hudson.ClassicPluginStrategy;
import hudson.ClassicPluginStrategy.DetachedPlugin;
import hudson.Plugin;
import hudson.PluginManager;
import hudson.PluginManagerUtil;
import hudson.PluginWrapper;
@@ -44,6 +45,7 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

@@ -81,6 +83,43 @@ public void upgradeFromJenkins2() {
});
}

@Issue("JENKINS-48604")
@Test
@LocalData
public void upgradeFromJenkins2WithNewerDependency() {
VersionNumber since = new VersionNumber("2.0");
rr.then(r -> {
List<DetachedPlugin> detachedPlugins = ClassicPluginStrategy.getDetachedPlugins(since);
assertThat("Plugins have been detached since the pre-upgrade version",
detachedPlugins.size(), greaterThan(1));
assertThat("Plugins detached between the pre-upgrade version and the current version should be installed",
getInstalledDetachedPlugins(r, detachedPlugins).size(), equalTo(detachedPlugins.size()));
Plugin scriptSecurity = r.jenkins.getPlugin("script-security");
assertThat("Script-security should be installed", scriptSecurity, notNullValue());
assertThat("Dependencies of detached plugins should not be downgraded",
scriptSecurity.getWrapper().getVersionNumber(), equalTo(new VersionNumber("1.34")));
assertNoFailedPlugins(r);
});
}

@Test
@LocalData
public void upgradeFromJenkins2WithOlderDependency() {
VersionNumber since = new VersionNumber("2.0");
rr.then(r -> {
List<DetachedPlugin> detachedPlugins = ClassicPluginStrategy.getDetachedPlugins(since);
assertThat("Plugins have been detached since the pre-upgrade version",
detachedPlugins.size(), greaterThan(1));
assertThat("Plugins detached between the pre-upgrade version and the current version should be installed",
getInstalledDetachedPlugins(r, detachedPlugins).size(), equalTo(detachedPlugins.size()));
Plugin scriptSecurity = r.jenkins.getPlugin("script-security");
assertThat("Script-security should be installed", scriptSecurity, notNullValue());
assertThat("Dependencies of detached plugins should be upgraded to the required version",
scriptSecurity.getWrapper().getVersionNumber(), equalTo(new VersionNumber("1.18.1")));
assertNoFailedPlugins(r);
});
}

@Test
public void newInstallation() {
rr.then(r -> {
Binary file not shown.
Binary file not shown.

0 comments on commit 1dc2c6d

Please sign in to comment.
You can’t perform that action at this time.