Reputation: 9648
I want to create a jenkins slave using command line. The is a document about setting up jenkins slave as a windows service and I followed the instruction there. I can run javaws http://10.121.33.4:8080/computer/Test-Jenkins-Slave-2/slave-agent.jnlp
to connect slave to master but the problem of this is it will get disconnect after the machine is restarted.
I think the best way to do this is to install slave as a service. So, I tried to follow the instruction again on that page. I have jenkins Slave installed as a service and the registry key added like below.
Service's property:
Registry values:
I wonder if I did anything incorrectly? Is the document missing something?
Upvotes: 17
Views: 97834
Reputation: 675
(Last 2019-09-20) The quickest and most reliable way that I've found to install a Jenkins Worker/Slave as a service is to:
Detailed steps and pictures below.
Note: Don't bother with modifying the registry, the embedded install makes the process quick, easy, and repeatable.
So lets say you've configured a node named "amberboch". On the worker/slave (i.e. "amberboch") machine:
Once the service has been installed, change the service's "log-on" credentials as needed for your particular installation. You may have to reset permissions or delete directories within the work-space if, whilst running in Administrator mode, a job happened to run and thereby created a work-space sub-folder (as any jobs that had run would have done so as the former administrator-privilaged user, and the regular Jenkins-user profile may not have proper permissions to the old workspace folders and files.
I hope this helps save you time and headaches in managing (imho) the best CI option I've come across.
Best regards, Rob
PS - I found another discussion that may also help: Install Jenkins slave as a Windows service in command line
(Update 2023-11-03) This method it becoming out of date given newer versions of Java. Please look into this bit of documentation from Cloud Bees: https://docs.cloudbees.com/docs/cloudbees-ci-kb/latest/client-and-managed-controllers/how-to-install-windows-agents-as-a-service
Upvotes: 27
Reputation: 1027
While other answers are effective, if you are like me and wanted the EXACT same agent experience you had before JavaWebstart died (when Oracle became the evil empire) and you couldn't just launch the JNLP file anymore... here it is....
The Java Agent (slave) gui that would allow you to configure the agent as a Windows Service did so via a open source package called WinSW (https://github.com/winsw/winsw).
All you have to do is utilize this tool in conjunction with the launch directives the Jenkins console provides you in the node configuration screens. While oddly NOT in the user guide for Jenkins, Cloudbees did make a KB about it here: https://docs.cloudbees.com/docs/cloudbees-ci-kb/latest/client-and-managed-masters/how-to-install-windows-agents-as-a-service
The net-net is this:
If you look at a Windows Service install from the old java gui you will see they make a jenkins-slave.exe, thats WinSW-x64.exe, in fact you can simply rename WinSW-x64.exe but if you do the .xml file must match for the INSTALL command to work.
Cheers!
Upvotes: 2
Reputation: 51
The easiest way to set up Jenkins node (slave) as a service is to use https://nssm.cc/
C:\
driveC:\nssm-2.24\win54>nssm install "JenkinsAgent"
startagent.bat
available in JenkinsYou can also configure user you want to use for running jenkins jobs.
Upvotes: 1
Reputation: 129
I have taken the
from a Jenkins 'master' installation. Next I have adapted the XML to contains the startup parameters for 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 the XML I have also: - edited the fields for id,name,description to my preferences - removed the content of the 'extensions' block
After that I can just start the windows service running an 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 in principle the same as starting the Jenkins master service.
Upvotes: 3
Reputation: 1
service may need to be started explicitly after system startup. You may need to:
or
Upvotes: 0