Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use java hudson.remoting.jnlp.Main not java -jar agent.jar #125

Merged
merged 2 commits into from
Sep 15, 2023

Conversation

jglick
Copy link
Member

@jglick jglick commented Sep 14, 2023

Allows agents to connect to a Jenkins controller using a non-public URL after jenkinsci/jenkins#4839. KostyaSha/yet-another-docker-plugin#288 (comment) gives some background.

</f:entry>
<f:entry title="Windows Command" field="windowsCommand">
<f:textbox value="${dockerSwarmAgentTemplate.windowsCommand}" default="powershell.exe &amp; { Invoke-WebRequest -TimeoutSec 20 -OutFile agent.jar %DOCKER_SWARM_PLUGIN_JENKINS_AGENT_JAR_URL%; if($?) { java -jar agent.jar -jnlpUrl %DOCKER_SWARM_PLUGIN_JENKINS_AGENT_JNLP_URL% -secret %DOCKER_SWARM_PLUGIN_JENKINS_AGENT_SECRET% -noReconnect } }"/>
<f:textbox value="${dockerSwarmAgentTemplate.windowsCommand}" default="powershell.exe &amp; { Invoke-WebRequest -TimeoutSec 20 -OutFile agent.jar %DOCKER_SWARM_PLUGIN_JENKINS_AGENT_JAR_URL%; if($?) { java -classpath agent.jar hudson.remoting.jnlp.Main -headless -url %DOCKER_SWARM_PLUGIN_JENKINS_URL% -noreconnect %DOCKER_SWARM_PLUGIN_JENKINS_AGENT_SECRET% %DOCKER_SWARM_PLUGIN_JENKINS_AGENT_NAME% } }"/>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows version untested.

@@ -10,10 +10,10 @@
<f:textbox value="${dockerSwarmAgentTemplate.image}" default="java:8"/>
</f:entry>
<f:entry title="Unix Command" field="unixCommand">
<f:textarea value="${dockerSwarmAgentTemplate.unixCommand}" default="sh&#10;-cx&#10;curl --connect-timeout 20 --max-time 60 -o agent.jar $DOCKER_SWARM_PLUGIN_JENKINS_AGENT_JAR_URL &amp;&amp; java -jar agent.jar -jnlpUrl $DOCKER_SWARM_PLUGIN_JENKINS_AGENT_JNLP_URL -secret $DOCKER_SWARM_PLUGIN_JENKINS_AGENT_SECRET -noReconnect -workDir /tmp"/>
<f:textarea value="${dockerSwarmAgentTemplate.unixCommand}" default="sh&#10;-cx&#10;curl --connect-timeout 20 --max-time 60 -o agent.jar $DOCKER_SWARM_PLUGIN_JENKINS_AGENT_JAR_URL &amp;&amp; java -classpath agent.jar hudson.remoting.jnlp.Main -headless -url $DOCKER_SWARM_PLUGIN_JENKINS_URL -noreconnect -workDir /tmp $DOCKER_SWARM_PLUGIN_JENKINS_AGENT_SECRET $DOCKER_SWARM_PLUGIN_JENKINS_AGENT_NAME"/>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending this PR, you can replace $DOCKER_SWARM_PLUGIN_JENKINS_URL with ${DOCKER_SWARM_PLUGIN_JENKINS_AGENT_JAR_URL%%jnlpJars/agent.jar}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can or should?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, to rephrase & expand: if you are running 1.11 but wish to access Jenkins HTTP via a different host than the canonical root URL, for example because you are running in Kubernetes and Swarm is inside the network and connections to the Jenkins controller should not exit the network and then come back in via ingress, then it is possible to configure that using a command like the one above but since $DOCKER_SWARM_PLUGIN_JENKINS_URL is not defined you would need to obtain the URL another way, such as with shell scripting ${DOCKER_SWARM_PLUGIN_JENKINS_AGENT_JAR_URL%%jnlpJars/agent.jar}. When 1.12 defined the new variable, then you could switch to the simpler form suggested here.

@Roemer
Copy link
Collaborator

Roemer commented Sep 15, 2023

Thanks, seems to make sense.

@Roemer Roemer merged commit 7aba39f into jenkinsci:master Sep 15, 2023
1 check failed
@jglick jglick deleted the direct-launch branch September 15, 2023 12:41
@jglick
Copy link
Member Author

jglick commented Dec 11, 2023

As of jenkinsci/remoting#677 java -classpath agent.jar hudson.remoting.jnlp.Main -headless ran be simplified to just java -jar agent.jar. Also the two positional arguments are better made explicit as -secret and -name, respectively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants