Skip to content
Permalink
Browse files

[JENKINS-48899] Do not downgrade detached plugins when upgrading Jenk…

…ins (#3229)

* Reproduce JENKINS-48899

* Do not downgrade installed detached plugins

(cherry picked from commit d629897)
  • Loading branch information...
dwnusbaum authored and olivergondza committed Jan 21, 2018
1 parent bed6ccd commit 7b6c86dc581e573a91802639647630ae40d8e208
@@ -705,13 +705,14 @@ public boolean accept(File dir, String name) {
// If this was a plugin that was detached some time in the past i.e. not just one of the
// plugins that was bundled "for fun".
if (ClassicPluginStrategy.isDetachedPlugin(name)) {
// If it's already installed and the installed version is older
// than the bundled version, then we upgrade. The bundled version is the min required version
// for "this" version of Jenkins, so we must upgrade.
VersionNumber installedVersion = getPluginVersion(rootDir, name);
VersionNumber bundledVersion = getPluginVersion(dir, name);
if (installedVersion != null && bundledVersion != null && installedVersion.isOlderThan(bundledVersion)) {
return true;
// If the plugin is already installed, we need to decide whether to replace it with the bundled version.
if (installedVersion != null && bundledVersion != null) {
// If the installed version is older than the bundled version, then it MUST be upgraded.
// If the installed version is newer than the bundled version, then it MUST NOT be upgraded.
// If the versions are equal we just keep the installed version.
return installedVersion.isOlderThan(bundledVersion);
}
}

@@ -120,6 +120,25 @@ public void upgradeFromJenkins2WithOlderDependency() {
});
}

@Issue("JENKINS-48899")
@Test
@LocalData
public void upgradeFromJenkins2WithNewerPlugin() {
// @LocalData has command-launcher 1.2 installed, which should not be downgraded to the detached version: 1.0.
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 commandLauncher = r.jenkins.getPlugin("command-launcher");
assertThat("Installed detached plugins should not be overwritten by older versions",
commandLauncher.getWrapper().getVersionNumber(), equalTo(new VersionNumber("1.2")));
assertNoFailedPlugins(r);
});
}

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

0 comments on commit 7b6c86d

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