Sitting behind a corporate proxy may give you some additional security but it's often challenging to get things done. I really had some troubles to get the groovy script in jenkins to use the proxy server.
Problem
We currently still use Jenkins for Continuous Delivery. This is usually fine as most stuff is internally. However with the adoption of Azure, things get slightly more difficult. Mainly cause connections to Azure from Jenkins have to be routed via the the corporate proxy. Our Jenkins slave in question is running on Windows where we have configured the proxy as part of the operating system. This seems to work well, even in Jenkins.
Looking at our code, which runs azcopy to deploy static web pages to a CDN looks as follows:
The runCommand will execute the command on the available shell, in case of Windows, on a cmd-shell. The route to the target goes over the proxy, which works fine. Probably cause it uses the proxy settings from Windows, as it does when you execute the command manually on a cmd-shell.
As an extension to the above, we also need to regurarily purge the cache, as otherwise the deployment is very slow. So we extended the groovy code to do that:
However when executing the code, the proxy settings seems to be ignored:
Using jenkins arguments
I though, maybe one has to also pass the proxy settings as part of the jenkins setup. Hence I modified jenkins-slave.xml and pass the
Still, I have the same result:
Using System.getProperties()
After searching, I found this, which recommends to use System.getProperties():
Unfortunately this made things even worse as it looks like the settings are applied to the Jenkins master, cause after running the pipeline once, subsequent runs did not even start, as checkout was not possible:
Which makes sense, cause I did not provide any nonProxyHosts, so everything is routed trough the proxy - well Bitbucket is internal, so this will not work trough the proxy. However, we don’t want the proxy settings changed on master but only on the slave. So let’s revert the changes, you can - within Jenkins - open a console on the built-in host, i.e. https://cd.intra/jenkins/computer/(built-in)/script and run