docker icon indicating copy to clipboard operation
docker copied to clipboard

Jenkins update center behind proxy problem

Open Jorkata13 opened this issue 2 years ago • 5 comments

Jenkins and plugins versions report

Environment
Paste the output here

What Operating System are you using (both controller, and any agents involved in the problem)?

I am using Windows 10 environment for building jenkins docker image. The docker installed on the windows is behind corporative proxy so when I am trying to build the jenkins I have to parse http_proxy and https_proxy on the dockerfile.

Reproduction steps

  1. I created jenkins dockerfile and added the proxy like that (the proxy is comming from build-args): FROM jenkins/jenkins:lts

Configure proxy server

ENV http_proxy $HTTP_PROXY ENV https_proxy $HTTPS_PROXY ENV HTTP_PROXY $HTTP_PROXY ENV HTTPS_PROXY $HTTPS_PROXY

  • I added both with lower and uppercase.
  1. I added some packages that has to be installed on the jenkins master and for them everything is working. Without the proxy I cant download any packages... so the proxy is working fine: RUN apt-get update && apt-get install -y git git-lfs wget nodejs

  2. But when I copied the plugins.txt file and tried to install the plugins with jenkins-plugin-cli command it gives an error that cant reach the update center: COPY plugins.txt /usr/share/jenkins/plugins.txt RUN jenkins-plugin-cli --plugin-file /usr/share/jenkins/plugins.txt

Expected Results

Expected results was to download everything correctly. I tried to manage that in my local environment where there is no proxy behind the docker and everything is working correctly but behind proxy the problem appears.

I find a way to work around it with this command: RUN java -Dhttps.proxyHost=$HTTPS_PROXY -Djdk.http.auth.tunneling.disabledSchemes= -Dhttps.proxyPort=$PORT -Dhttps.proxyUser=$USER -Dhttps.proxyPassword=$PASS -jar /opt/jenkins-plugin-manager.jar -f /usr/share/jenkins/plugins.txt

Actual Results

  1. The result from the proxy problem. #7 1.939 Unable to retrieve JSON from https://updates.jenkins.io/update-center.json?version=2.346.2: updates.jenkins.io: Name or service not known #7 1.940 Unable to retrieve JSON from https://updates.jenkins.io/update-center.json?version=2.346.2: updates.jenkins.io #7 1.943 Error getting update center json

  2. With the work around way I succeeded installing the plugins but still has a problem with the update center in the Jenkins UI: Update information obtained: N/A ago There were errors checking the update sites: UnknownHostException: updates.jenkins.io

Anything else?

I thing that the problem is when we try to pass the proxy variables to the container as ENV variables they are not passed correctly to JAVA, because I can download packages and anything that I want, but JAVA don't know about the proxy so I cant download anything from the jenkins update center.

Jorkata13 avatar Aug 04 '22 07:08 Jorkata13

Java doesn't use system proxy values by default,

The script supports a JAVA_OPTS environment variable

JAVA_OPTS=-Dhttps.proxyHost=$HTTPS_PROXY -Djdk.http.auth.tunneling.disabledSchemes= -Dhttps.proxyPort=$PORT -Dhttps.proxyUser=$USER -Dhttps.proxyPassword=$PASS jenkins-plugin-cli

or

ENV JAVA_OPTS=-Dhttps.proxyHost=$HTTPS_PROXY -Djdk.http.auth.tunneling.disabledSchemes= -Dhttps.proxyPort=$PORT -Dhttps.proxyUser=$USER -Dhttps.proxyPassword=$PASS
RUN jenkins-plugin-cli...

timja avatar Aug 04 '22 07:08 timja

Thank you I will try it now

Jorkata13 avatar Aug 04 '22 08:08 Jorkata13

Okay I tried this but still has some issues: ENV JAVA_OPTS=-Dhttps.proxyHost=$HTTPS_PROXY -Djdk.http.auth.tunneling.disabledSchemes= -Dhttps.proxyPort=$PORT -Dhttps.proxyUser=$USER -Dhttps.proxyPassword=$PASS RUN jenkins-plugin-cli...

I tried this but still same shit .. so I just tried this configuration

ENV JAVA_OPTS=-Dhttps.proxyHost=$HTTPS_PROXY -Djdk.http.auth.tunneling.disabledSchemes= -Dhttps.proxyPort=$PORT -Dhttps.proxyUser=$USER -Dhttps.proxyPassword=$PASS

RUN java -Dhttps.proxyHost=$HTTPS_PROXY -Djdk.http.auth.tunneling.disabledSchemes= -Dhttps.proxyPort=$PORT -Dhttps.proxyUser=$USER -Dhttps.proxyPassword=$PASS -jar /opt/jenkins-plugin-manager.jar -f /usr/share/jenkins/plugins.txt

RUN jenkins-plugin-cli...

This ended with success ... absolutely no logic .... but now when I enter in the jenkins UI I can update the plugins, so the previous problem with the update center in the UI is gone but some plugins still has problem: Checking internet connectivity Checking update center connectivity java.net.ConnectException: Connection refused (Connection refused)

Only for 6 plugins of 120 ...

The strange thing is if I try to install the plugins with the plugin-manager.jar everything is okay but why with the jenkins-plugin-cli is not working ?

Any suggestions ?

Jorkata13 avatar Aug 04 '22 09:08 Jorkata13

possibly needs quotes you could exec into the container and experiment more

timja avatar Aug 04 '22 09:08 timja

Hello @Jorkata13 , there are multiple elements at stake here:

  • The Dockerfile instruction ENV (ref. https://docs.docker.com/engine/reference/builder/#env) is not a shell command at all. So any variable like $HTTP_PROXY are only interpolated during the docker build phase with the build argument values. It looks good on what you describe, but since you only share partial information, it's hard to help catching the issue: can you share at least the whole Dockerfile and the command that you ran (with the values redacted)?

  • As recommended by @timja , you might want to debug a bit more:

    • Add the flag --progress=plain to your docker build command in order to view the full build log (ref. https://docs.docker.com/engine/reference/commandline/buildx_build/#progress)
    • Run the script with debug enabled: RUN bash -x "$(which jenkins-plugin-cli)" to view the full command line from https://github.com/jenkinsci/docker/blob/master/jenkins-plugin-cli.sh#L9 that is executed in the case that does not work for you

And share the result there if you need more help.

dduportal avatar Aug 09 '22 12:08 dduportal