jenkinsci / docker-swarm-plugin

Jenkins plugin which allows to add a Docker Swarm as a cloud agent provider
https://plugins.jenkins.io/docker-swarm/
MIT License
55 stars 47 forks source link

Default agent template default command no longer seems to work in latest jenkins 2.278 #105

Open loreleimccollum-work opened 3 years ago

loreleimccollum-work commented 3 years ago

We logged this bug https://issues.jenkins.io/browse/JENKINS-64842 because we noticed on newer jenkins(2.278) our swarm no longer worked. That we were not seeing agents spin up as we had on older jenkins(2.257) version. They were getting stuck because only ONE url was being passed to the agent for Jenkins. Where on the older jenkins it had two urls Some core changes to jenkins had been made in this area we believe from the tickets, change log we reviewed

Basically I think the default command the plugin provides here https://github.com/jenkinsci/docker-swarm-plugin/blob/4a3ec4106ff846a52302abd1f8cc9cb1c80b01e0/src/main/resources/org/jenkinsci/plugins/docker/swarm/DockerSwarmAgentTemplate/config.jelly#L13 may need to be updated due to jenkins changes

This is what works for us sh -cx curl --connect-timeout 20 --max-time 60 -o agent.jar $DOCKER_SWARM_PLUGIN_JENKINS_AGENT_JAR_URL && java -classpath agent.jar hudson.remoting.jnlp.Main -headless -url http://172.17.0.1:8080/ -workDir /tmp $DOCKER_SWARM_PLUGIN_JENKINS_AGENT_SECRET $DOCKER_SWARM_PLUGIN_JENKINS_AGENT_NAME

Our case is that the Global config for Jenkins URL is not accessible directly so we have essentially two urls to hit our jenkins one thats external and one thats internal. In the newer jenkins the internal url lis no longer passed for the urls the agent jar uses.

Can provide more info if necessary but want to log this as we spent two days debugging this and in the event someone else has this same issue this could help them

blaise-io commented 3 years ago

Thanks @loreleimccollum-work, your solution works for us on Jenkins 2.277.1 and Docker Swarm 1.11 and saved us a lot of time and work.

We were running into the same issue where we needed agents to connect to the internal Jenkins url because the external Jenkins url was using OAuth authentication. @loreleimccollum-work's solution bypasses the JNLP config file generated by Docker Swarm and initializes hudson.remoting.jnlp.Main directly, which allows setting a custom, internal -url.

We're starting the agent like this now: sh -cx curl --connect-timeout 20 --max-time 60 -o agent.jar $DOCKER_SWARM_PLUGIN_JENKINS_AGENT_JAR_URL && java -classpath agent.jar hudson.remoting.jnlp.Main $DOCKER_SWARM_PLUGIN_JENKINS_AGENT_SECRET $DOCKER_SWARM_PLUGIN_JENKINS_AGENT_NAME -workDir /jenkins -headless -noreconnect -internalDir remoting -url http://10.254.254.1:8080/