private void buildProxyEnvVars(EnvVars env, TaskListener log) throws IOException, URISyntaxException { ProxyConfiguration proxycfg = Jenkins.getActiveInstance().proxy; if (proxycfg == null) { // no proxy configured return; } String userInfo = proxycfg.getUserName(); // append password only if userName if is defined if (userInfo != null && proxycfg.getEncryptedPassword() != null) { userInfo += ":" + Secret.decrypt(proxycfg.getEncryptedPassword()); } String proxyURL = new URI("http", userInfo, proxycfg.name, proxycfg.port, null, null, null).toString(); // refer to https://docs.npmjs.com/misc/config#https-proxy env.put("HTTP_PROXY", proxyURL); env.put("HTTPS_PROXY", proxyURL); String noProxyHosts = proxycfg.noProxyHost; if (noProxyHosts != null) { if (noProxyHosts.contains("*")) { log.getLogger().println("INFO: npm doesn't support wild card in no_proxy configuration"); } // refer to https://github.com/npm/npm/issues/7168 env.put("NO_PROXY", noProxyHosts.replaceAll("(\r?\n)+", ",")); } }
/** * Initialize a {@link WebProxySettings} from a Jenkins {@link ProxyConfiguration}. * * @param proxyConfiguration the proxy settings as obtained from Jenkins. * May be {@code null}, meaning there is no proxy configured. */ public WebProxySettings(final ProxyConfiguration proxyConfiguration) { if (proxyConfiguration != null) { this.hostName = proxyConfiguration.name; this.port = proxyConfiguration.port; this.proxyUser = proxyConfiguration.getUserName(); this.noProxyHostPatterns = copyNoProxyHostPatterns(proxyConfiguration.getNoProxyHostPatterns()); this.proxySecret = Secret.fromString(proxyConfiguration.getEncryptedPassword()); } else { this.hostName = null; this.port = -1; this.proxyUser = null; this.proxySecret = null; this.noProxyHostPatterns = copyNoProxyHostPatterns(null); } }