Skip to content

Commit

Permalink
Add JENKINS_UC_DOWNLOAD_URL for custom update center url
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmacoo committed Oct 14, 2021
1 parent cddafe3 commit a28e664
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions plugin-management-library/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
<version>2.31.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.stefanbirkner</groupId>
<artifactId>system-rules</artifactId>
<version>1.19.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a28e664

Please sign in to comment.