Jenkins Windows slave agent as a service

Jenkins Windows slave agentJenkins 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:

Installation error

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.

Resolution

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”:

Send javaws.exe 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!

Target - path to the jnlp

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.

Run as Administrator

After that Jenkins Windows slave agent will connect with the master node and you would be able to install agent as a service.

Install 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:

Service Jenkins

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.

3 Replies to “Jenkins Windows slave agent as a service”

  1. Hi.
    I run command thrue jenkins slave that starts a window process, but in the end the of the jenkins job the process is gone…..

    I run indeical command on another slave, and the process is being kept alive.
    I can not se any difference.
    What am i missing? anyone?

    1. Hi!

      Sounds weird. Is there any difference between the slave nodes? I mean between both Windows machines? Have they been deployed the same way and have the same configuration? Can you reproduce this problem on other machines (by creating the new one, and another new one, and another…) or this occurs only on this one Windows machine?

      What are the logs say? You can find them in the Jenkins Master – nodes section (Manage Jenkins -> Manage Nodes -> Choose your node -> Log). There should be some information why the connection was lost.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.