Skip to content

Commit

Permalink
[JENKINS-48899] Do not downgrade detached plugins when upgrading Jenk…
Browse files Browse the repository at this point in the history
…ins (#3229)

* Reproduce JENKINS-48899

* Do not downgrade installed detached plugins
  • Loading branch information
dwnusbaum authored and oleg-nenashev committed Jan 21, 2018
1 parent 4cbeed7 commit d629897
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
11 changes: 6 additions & 5 deletions core/src/main/java/hudson/PluginManager.java
Expand Up @@ -706,13 +706,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);
}
}

Expand Down
19 changes: 19 additions & 0 deletions test/src/test/java/jenkins/install/LoadDetachedPluginsTest.java
Expand Up @@ -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 -> {
Expand Down
Binary file not shown.

0 comments on commit d629897

Please sign in to comment.