How to configure Jenkins Slave to start as a Windows service using the command line?

I want to create a jenkins slave using the command line. This is a document on setting up slav-jenkins as a Windows service, and I followed the instructions there. I can run javaws http://10.121.33.4:8080/computer/Test-Jenkins-Slave-2/slave-agent.jnlp to connect the slave to the master, but the problem is that it will shut down after rebooting the machine.

I think the best way to do this is to install slave as a service. So, I tried again to follow the instructions on this page. I have a Jenkins Slave installed as a service and a registry key has been added as shown below.

Service Property:
enter image description here

Registry Values:
enter image description hereenter image description here

I wonder if I did something wrong? Is the document missing?

+11
source share
3 answers

The last time I edited this answer (2019-09-20), the fastest and most reliable way to install Jenkins Worker / Slave as a service is to use the endpoint "/slave-agent.jnlp" to load the jnlp file, run it and then select “File” => “Install as Service” from its GUI.

No worries about registry changes, the built-in installation makes the process fast, simple and repeatable.

Suppose you set up a node named "amberboch". By worker / slave machine (i.e., "amberboh"):

  1. Open a browser and enter the Jenkins URL for the new site (or click the site on the Sites page in Jenkins) and create the site in Jenkins, as usual.
  2. Once the site is created, go to the site (Jenkins> Nodes> amberboch) and include "/slave-agent.jnlp" at the end of the browser URL (for example, " http: // jenkins: 8080 / computer / computer / amberboch / slave-agent.jnlp ") download the jnlp file. Notice "slave-agent.jnlp" is added manually Save the file
  3. Run the slave-agent.jnlp file with administrator privileges. (You can specify Java / javaws to launch it using the "Java (TM) Web Start Launcher")
  4. Select the option "File" => "Install as a service" in the slave-agent.jnlp GUI

After installing the service, change the login credentials of the service required for the particular installation. You may need to reset permissions or delete directories in the workspace if a task occurred during operation in administrator mode and as a result a workspace subfolder was created (since all running tasks would be performed in the same way as a former user with administrator rights and a regular profile Jenkins user may not have proper permissions for old folders and workspace files.

I hope this helps you save time and headaches in managing (imho) the best CI option I've come across. Sincerely.

+13
source
Service

You may need to start explicitly after starting the system. You may need to:

  • go to the "log in" tab and start the service as a user with administrator rights on the computer.

or

  1. Launch the jenkins agent through the window scheduler using the instructions here: https://wiki.jenkins-ci.org/display/JENKINS/Launch+Java+Web+Start+slave+agent+via+Windows+Scheduler
0
source

I took

  • jenkins.exe
  • jenkins.exe.config
  • jenkins.xml

from the installation of master Jenkins. Then I adapted the XML to contain the launch options of my slave. This gives something like:

 <executable>%JAVA_HOME%\bin\java.exe</executable> <arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "C:\Tools\jenkins_slave\slave_95\agent.jar" -jnlpUrl http://jenkins_master:9090/computer/slave_95/slave-agent.jnlp -secret 999999999999999999999999999999999999999999 -workDir "C:\jenkins_slaves_workdir"</arguments> 

In XML, I also have: - edited the fields for id, name, description in my preferences - deleted the contents of the extension block

After that, I can simply start the Windows service by running the admin shell on the slave using the command:

 sc create <service_name> binpath= "C:\Tools\jenkins_slave\slave_95\Jenkins.exe" start= auto 

Which is basically the same as launching the Jenkins master service.

0
source

Source: https://habr.com/ru/post/970918/


All Articles