In Jenkins many time we have to add windows machine as slave, where we need the agent to be up and running as windows service.
There are many ways to do it, but I struggled to find the correct configuration steps. I used windows resource toolkit to make it work and adding the steps here.
(A) Adding the windows slave in Jenkins server :
1. Add the agent in Jenkins Master with Launch Method : Launch Via Java Web Start
(B) Creating the Service in windows Server for starting the slave agent: (In Windows Server 2016)
1. Download and install the Java 8.
2. Down and Install Windows Resource Kit Tools (https://www.microsoft.com/en-us/download/details.aspx?id=17657)
3. Create a blank service called “Jenkins Slave” by running the following from a command prompt
“C:\Program Files (x86)\Windows Resource Kits\Tools\instsrv.exe” “Jenkins Slave” “C:\Program Files (x86)\Windows Resource Kits\Tools\srvany.exe”
4. Open Registry Editor and go to below location :
Now Follow the below steps carefully.
- Create a string value “Description”
- Populate it with “Jenkins Continuous Integration Slave”
- Create a new key “Parameters”
- Under “Parameters” create a new string value “Application”
- Populate it with the full path to java.exe, something like “C:\sapjvm_8\bin\java.exe”
- Under “Parameters” Create a new string value “AppParameters”
- Populate it with
“-jar E:\jenkins_agent\agent.jar -jnlpUrl http://m1-hostname.lab.saas.company.corp:8080/computer/hostame-of-machone/slave-agent.jnlp -secret <secret-name> -workDir E:\jenkinsWorkSpace”
- The slave.jar should point to the correct location
- The Jenkins master machine name should be correct
- The new Jenkins slave machine should be correct
- Make sure you use the secret for this machine that you copied from the master when adding the new node
Open the Services application from Control Panel – Administrative Tools, find the “Jenkins Slave” service, right click on the service and go to “Properties”.
- Go to the “Recovery” tab and change “First failure” and “Second failure” to “Restart the Service” – occasionally we found it wouldn’t start up first time out
- Go to the “Log On” tab and set an account and password- we found that using an account with local admin rights on the slave machine worked best but this is probably unnecessary
- Go to the “General” tab and change the “Startup type” to “Automatic” – make sure the service
- starts up when you restart the slave
- Click the “OK” button
- Now start the service
6. The service will run by default during startup of the windows machine.
7. Now Verify the agent is up and running in Jenkins Web Page.