JNLP Connections are deprecated in Jenkins what is the new recommended way connecting a windows agent to jenkins?
Asked Answered
S

2

8

As the title already states JNLP connections are deprecated. Jenkins also gives a message and a hyperlink to https://en.wikipedia.org/wiki/Java_Web_Start#Deprecation.

So what's the recommended way to attach a Windows agent to Jenkins now? There seems to be no real good guide on https://jenkins.io covering that topic.

Snazzy answered 24/2, 2020 at 8:46 Comment(0)
M
13

There are two options: Either use an open source alternative for Java Web Start or use the Jenkins service wrapper instead. The latter gives you the most control.

Open Source Alternative to Java Web Start

There is an open source replacement called OpenWebStart which is based on IcedTeaWeb.

More information: Java Web Start is dead - long live OpenWebStart!

OpenWebStart is an open source implementation of the WebStart and JNLP standards (JSR-56).

[...]

In IcedTeaWeb we are currently working on mapping the JNLP spec and supporting its functions to the greatest extent possible. In addition to OpenWebStart, which uses IcedTeaWeb as its core, IcedTeaWeb is also used within AdoptOpenJDK to provide minimal WebStart in the Java 8 releases of AdoptOpenJDK. However, these are limited compared to OpenWebStart because they can only use the current JVM to run JNLP-based applications.

Using the Jenkins Service Wrapper

When installing Jenkins service through the service wrapper (winsw-*.exe), Java Web Start is no longer required. It seems that JNLP protocol is still used behind the scenes, so it may still have some deprecation issue in the future.

Steps (assuming you have already set up the node in Jenkins master):

  1. Download latest service wrapper from http://repo.jenkins-ci.org/releases/com/sun/winsw/winsw/ (e. g. "winsw-2.2.0-net4.exe")
    Place it in the Custom WorkDir path and rename it to "jenkins-agent.exe"

  2. Download "agent.jar": http://YourJenkinsServer:8080/jnlpJars/agent.jar
    Place it in the Custom WorkDir path and rename it to "agent.jar"

  3. Create "jenkins-agent.xml" in the same directory:

     <service>
       <id>YourJenkinsAgentServiceId</id>
       <name>Your Jenkins Agent Service Name</name>
       <description>This service runs an agent for Jenkins automation server.</description>
       <executable>C:\Program Files\Java\bin\java.exe</executable>
       <arguments>-Xrs -jar "%BASE%\agent.jar" -jnlpUrl http://YourJenkinsServer:8080/manage/computer/YourNodeName/jenkins-agent.jnlp -secret YourSecretStringConsistingOfHexadecimalCharacters -workDir=C:\YourNodeWorkDir</arguments>
       <logmode>rotate</logmode>
       <onfailure action="restart" />
       <download from="http://YourJenkinsServer:8080/jnlpJars/agent.jar" to="%BASE%\agent.jar"/>
       <extensions>
         <extension enabled="true" className="winsw.Plugins.RunawayProcessKiller.RunawayProcessKillerExtension" id="killOnStartup">
           <pidfile>%BASE%\jenkins_agent.pid</pidfile>
           <stopTimeout>5000</stopTimeout>
           <stopParentFirst>false</stopParentFirst>
         </extension>
       </extensions>
     </service>
    
  4. Adjust "jenkins-agent.xml" according to your environment. The java.exe should be the same version as used by Jenkins. Make sure to adjust all strings I prefixed with "Your" and also the path to "java.exe". You'll find the secret string and correct jnlpUrl on the node configuration page of Jenkins master (e. g. http://YourJenkinsServer:8080/manage/computer/YourNodeName/).
    Official documentation

  5. Create "jenkins-agent.exe.conf" file to prevent the executable from running on an earlier version of the .NET Framework.

     <configuration>
       <startup>
         <supportedRuntime version="v4.0"/>
       </startup>
     </configuration>
    
  6. Launch "cmd.exe" as administrator and navigate to directory of "jenkins-agent.exe".

  7. Install the service:
    jenkins-agent.exe install

  8. Launch the service:
    sc start YourJenkinsAgentServiceId

Notes:

  • For simplicity I have used http protocol only. When the connection is working, I recommend to switch to https for improved security.
    • If you are using a self-signed certificate on the Jenkins server (typically in a LAN), you have to install the certificate on the agent into the Java certificate store (as the Windows certificate store is ignored by Java). This can be done using Java's keytool (more information).
Mims answered 25/2, 2020 at 16:20 Comment(5)
Hi, you know why i am not able to run the service as local System user ? if i run the service as my admin username , its connecting to master . its win server2016.Tallis
@Tallis I'm sure I had it running as Local System at one point. Are there any related entries in Windows event protocol?Mims
service log shows : INFO: Both error and output logs will be printed to D:\js\remoting Feb 20, 2022 5:49:28 PM hudson.remoting.jnlp.Main$CuiListener status INFO: Locating server among [serverip:8080/ci/ui/] Feb 20, 2022 5:49:28 PM hudson.remoting.jnlp.Main$CuiListener error SEVERE: serverip:8080/ci/ui/tcpSlaveAgentListener is invalid: 403 Forbidden java.io.IOException: serverip:8080/ci/ui/tcpSlaveAgentListener is invalid: 403 Forbidden at org.jenkinsci.remoting.engine.JnlpAgentEndpointResolver.resolve(JnlpAgentEndpointResolver.java:219)Tallis
@Tallis Sorry, still no idea. This is propably better asked on serverfault.comMims
its now resolved, seems the access issues with the D:\js\remoting folder. running the service as Local System , and system user has full access. But when i allow write access to other users , its started working. which is weird.Tallis
G
0

The easiest method is using WinSW (Windows Service Wrapper) to connect a Windows agent to Jenkins, you can follow these steps: Download the WinSW executable from the official website and save it in a directory on your Windows machine.

Create a new directory for the Jenkins agent on the Windows machine. This directory will be used as the "Remote FS root" when configuring the agent in Jenkins.

Create a new XML file in the directory where you saved the WinSW executable, and name it "jenkins-slave.xml". You can use any text editor to create this file.

Open the "jenkins-slave.xml" file and add the following content:

<service>
    <id>jenkins-slave</id>
    <name>Jenkins Slave</name>
    <description>This service runs a Jenkins agent on this machine.</description>
    <executable>C:\Program Files\Java\jdk1.8.0_221\bin\java.exe</executable>
    <arguments>-jar C:\Path\To\slave.jar -jnlpUrl http://jenkins-server:port/computer/slave-name/slave-agent.jnlp -secret abcdef1234567890 -workDir C:\Path\To\Agent\Directory</arguments>
    <logmode>rotate</logmode>
</service>

Replace "jenkins-server" and "port" with the hostname and port number of your Jenkins server, "slave-name" with the name you want to give to your Windows agent in Jenkins, "abcdef1234567890" with the secret key provided by Jenkins, and "C:\Path\To\Agent\Directory" with the path to the directory you created for the Jenkins agent.

Save the "jenkins-slave.xml" file.

Open a command prompt as an administrator and navigate to the directory where you saved the WinSW executable.

Run the following command to install the Jenkins agent as a Windows service:

winsw.exe install

Run the following command to start the Jenkins agent service:

net start "Jenkins Slave"

In the Jenkins web interface, go to "Manage Jenkins" > "Manage Nodes and Clouds" > "New Node" to create a new node for the Windows agent.

Enter a name for the node and select "Permanent Agent". Click "OK".

On the next screen, enter the following information:

Remote root directory: The directory on the Windows machine where the agent should run. Labels: Any labels that you want to assign to the node. Launch method: "Launch agent via Java Web Start". Availability: "Keep this agent online as much as possible". Click "Save" to create the node.

In the node configuration screen, click "Launch" to launch the Windows agent. You should see the agent connect to the Jenkins master and show up as online.

Garris answered 9/5, 2023 at 6:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.