Run Jenkins as a Windows Server

Tejas Mane
2 min readJun 14, 2023

--

This blog provides step-by-step instructions on how to run Jenkins as a Windows service. Running Jenkins as a service ensures that it automatically starts when the system boots up and runs in the background, even if no user is logged in.

Prerequisite

  • Ensure that your Jenkins service is not running on the agent node on which you want to run the service.
  • To check this, go the Windows Services and check if Jenkins is running or not if it’s running then stop the service before proceeding further.

Download the following software & Configure Jenkins root directory

  1. Download the winSW-x64.exe file and copy it to the Jenkins root directory (provided during the agent node setup).
  2. Rename the winSW-x64.exe file to “jenkins-agent.exe”.
  3. Check the “sample-allOptions.xml” and “sample-minimal.xml” files on the winsw site for example configurations.
  4. To install Jenkins as a service, create an XML file (e.g., jenkins-agent.xml) based on the sample configurations.
  5. Open the Jenkins root directory (jenkins-agent) and create the jenkins-agent.xml file. Write the service configuration in the jenkins-agent.xml file, referring to the example configurations.
  6. You can also add <log mode=”roll” /> to xml file. This will create additional log files in the directory.
  7. Save the jenkins-agent.xml file in the Jenkins root directory.
  8. Download the agent.jar file from the Jenkins master and copy it into the Jenkins root directory.

Here is the Sample of XML file

<service>
<id>jenkins8080agent</id>
<name>Jenkins Agent for jenkins:8080</name>
<description>This service runs the agent process connected to jenkins:8080</description>
<executable>D:\\tools\\jdk-11.0.15.10-hotspot\\bin\\java.exe</executable>
<arguments>-jar D:\\tools\\jenkins-agent\\agent.jar -jnlpUrl <http://jenkins:8080/computer/windows/jenkins-agent.jnlp> -secret b66b6def580864901a50b9c8daaeea96f9e7f5537f02eb58bf5f6d1deae4155c -workDir "d:\\tools\\jenkins-agent"</arguments>
<log mode="roll" />
<onfailure action="restart" />
</service>

Download Link

winSW — https://github.com/winsw/winsw/releases/tag/v2.12.0

Installing the Service

  1. Open a terminal as an Administrator on the agent (Slave) node.
  2. Navigate using CLI to the Jenkins root directory where the jenkins-agent.exe and jenkins-agent.xml files are located.
  3. Run the command <name-of-exe> — help (i.e., jenkins-agent.exe — help) to see the available options.
  4. Install the service using the jenkins-agent.exe install command for the jenkins-agent.exe file.
  5. Verify that the service is installed and running using Windows Services.

At this point, you should have successfully configured and installed Jenkins as a Windows service. The service will now automatically start when the system boots up, allowing you to run Jenkins in the background without requiring a user to be logged in.

Thank You!

--

--

Tejas Mane

▪️ 🥑 DevOps ♾️ ▪️ AWS Community Builder ☁️ ▪️ Kubernetes ☸️ ▪️ Terraform 🚀 ▪️ Go 👨🏻‍💻 ▪️ Linux 🐧 ▪️ GitHub https://github.com/iamtejasmane