Jenkins is a fantastic tool for automation every process in your company/lab/your own projects. You can integrate your PowerCLI scripts with Ansible and even more utilities. I won’t describe Jenkins, because the are tons of pages (and also its own Wikipedia) which do it better than me. I want to focus on one problem. Run Jenkins Windows slave agent as a service inside the operating system.
Jenkins allows you to set up many workers. It can be a Linux as well as Windows machine. In the basic configuration, Jenkins has only one master node, on which is installed. For more distributed and flexible builds, it allows you to create something called “Permanent Agent”. It is a machine (physic, virtual machine, docker etc.) which has its own operating system and can run Jenkins’ jobs. Jenkins is written in Java, so it also communicates with its slaves by the java agents. You have to start these agents every time you reboot the system, stop the agent or interrupt agent’s work in every case. Jenkins Windows slave agent can be installed as a service, so you do not need to remember about starting the agent every time! But the problem begins here.
Problem with Jenkins Windows slave agent installation
One of the ways for running the java agent is using Java Web Start on the slave node. To do that, you need to download a .jnlp file from your master node to the slave, and run it with JWS. Usually there are no troubles with establishing the connection, but during the installation agent as a service you can see something like this:
You may think: “Hey, it’s simple! Let’s run .jnlp as Administrator!” – and you are right! It is so simple, but… .jnlp is not an executable file.
If you want to install Jenkins Windows slave agent as a service via Java Web Start, you should do the following steps:
At first you need to enter the Java directory and create a shortcut of the “javaws.exe” on the desktop. The best option in my opinion is to use a “send to desktop”:
Now you can check how the properties of the shortcut look like. As you can see, there is a “Target” field – it is what we are looking for. After the path of the executable file, we should insert the path of our .jnlp file. In this example you can see that I have downloaded .jnlp file to the C:\Users\emil.wypych\Downloads\slave-agent.jnlp. Please remember to insert that path after the quotation mark!
You can apply changes (nothing more should be modified) and close this window. Now it is the time for run the Java Web Start as Administrator. To do that you should choose the shortcut, use the right mouse button and select “Run as Administrator” from the menu.
After that Jenkins Windows slave agent will connect with the master node and you would be able to install agent as a service.
The process of the installation will complete successfully. To validate it you need to open Task Manager and search in the “Services” tab for something like this:
As you can see it is very easy to prepare Jenkins Windows slave agent. You have to keep in mind how to run Java Web Start and that .jnlp files are not executable.