diff --git a/README.md b/README.md index 81d8f87ca..e64cdbae4 100644 --- a/README.md +++ b/README.md @@ -70,9 +70,12 @@ Jenkins in a broken state. * `CACHE_DIR`: used to configure the directory where the plugins update center cache is located. By default it will be in `~/.cache/jenkins-plugin-management-cli`, if the user doesn't have a home directory when it will go to: `$(pwd)/.cache/jenkins-plugin-management-cli`. -* `JENKINS_UC_DOWNLOAD`: used to configure the URL from where plugins will be downloaded from. Often used to cache or to proxy the Jenkins plugin download site. -If set then all plugins will be downloaded through that URL. - +* `JENKINS_UC_DOWNLOAD`: used to configure the URL from where plugins will be downloaded from. When this value is set, it replaces the plugin download URL found in the `update-center.json` file with `${JENKINS_UC_DOWNLOAD}/plugins`. Often used to cache or to proxy the Jenkins plugin download site. +If set then all plugins will be downloaded through that URL. To use a custom URL, use `JENKINS_UD_DOWNLOAD_URL`. + +* `JENKINS_UC_DOWNLOAD_URL`: used to configure a custom URL from where plugins will be downloaded from. When this value is set, it replaces the plugin download URL found in the `update-center.json` file with `${JENKINS_UC_DOWNLOAD_URL}`. Often used to cache or to proxy the Jenkins plugin download site. +If set then all plugins will be downloaded through that URL. To use a conventional download center url, use `JENKINS_UD_DOWNLOAD`. + * `JENKINS_UC_HASH_FUNCTION`: used to configure the hash function which checks content from UCs. Currently `SHA1` (deprecated), `SHA256` (default), and `SHA512` can be specified. #### Plugin Input Format diff --git a/plugin-management-library/pom.xml b/plugin-management-library/pom.xml index e341692c6..01bad6217 100644 --- a/plugin-management-library/pom.xml +++ b/plugin-management-library/pom.xml @@ -70,6 +70,12 @@ 2.31.0 test + + com.github.stefanbirkner + system-rules + 1.19.0 + test + diff --git a/plugin-management-library/src/main/java/io/jenkins/tools/pluginmanager/impl/PluginManager.java b/plugin-management-library/src/main/java/io/jenkins/tools/pluginmanager/impl/PluginManager.java index 842d2550c..0dd5065ac 100644 --- a/plugin-management-library/src/main/java/io/jenkins/tools/pluginmanager/impl/PluginManager.java +++ b/plugin-management-library/src/main/java/io/jenkins/tools/pluginmanager/impl/PluginManager.java @@ -1169,8 +1169,11 @@ public String getPluginDownloadUrl(Plugin plugin) { } String jenkinsUcDownload = System.getenv("JENKINS_UC_DOWNLOAD"); + String jenkinsUcDownloadUrl = System.getenv("JENKINS_UC_DOWNLOAD_URL"); if (StringUtils.isNotEmpty(pluginUrl)) { urlString = pluginUrl; + } else if (StringUtils.isNotEmpty(jenkinsUcDownloadUrl)) { + urlString = appendPathOntoUrl(jenkinsUcDownloadUrl, pluginName, pluginVersion, pluginName + ".hpi"); } else if (StringUtils.isNotEmpty(jenkinsUcDownload)) { urlString = appendPathOntoUrl(jenkinsUcDownload, "/plugins", pluginName, pluginVersion, pluginName + ".hpi"); } else if ((pluginVersion.equals("latest") || plugin.isLatest()) && !StringUtils.isEmpty(jenkinsUcLatest)) { diff --git a/plugin-management-library/src/test/java/io/jenkins/tools/pluginmanager/impl/PluginManagerTest.java b/plugin-management-library/src/test/java/io/jenkins/tools/pluginmanager/impl/PluginManagerTest.java index 875affa04..6fe4485e1 100644 --- a/plugin-management-library/src/test/java/io/jenkins/tools/pluginmanager/impl/PluginManagerTest.java +++ b/plugin-management-library/src/test/java/io/jenkins/tools/pluginmanager/impl/PluginManagerTest.java @@ -20,6 +20,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.junit.contrib.java.lang.system.EnvironmentVariables; import org.junit.rules.TemporaryFolder; import static com.github.stefanbirkner.systemlambda.SystemLambda.tapSystemOutNormalized; @@ -48,6 +49,10 @@ public class PluginManagerTest { @Rule public final TemporaryFolder folder = new TemporaryFolder(); + + @Rule + public final EnvironmentVariables environmentVariables = new EnvironmentVariables(); + @Before public void setUp() { cfg = Config.builder() @@ -1104,6 +1109,10 @@ public void getPluginDownloadUrlTest() { String otherURL = dirName(cfg.getJenkinsUc().toString()) + "download/plugins/pluginName/otherversion/pluginName.hpi"; assertThat(pm.getPluginDownloadUrl(pluginOtherVersion)).isEqualTo(otherURL); + + Plugin pluginUrlOverride = new Plugin("pluginName", "pluginVersion", "https://mirror.server.com/path/pluginName/pluginVersion/pluginName.hpi", null); + environmentVariables.set("JENKINS_UC_DOWNLOAD_URL", "https://server.com/jenkins-plugins"); + assertThat(pm.getPluginDownloadUrl(pluginUrlOverride)).isEqualTo("https://server.com/jenkins-plugins/pluginName/pluginVersion/pluginName.hpi"); } @Test