Installing Jenkins as a Windows service

Skip to end of metadata
Go to start of metadata

Table Of Contents

Install Jenkins as a Windows service

NOTE: if you installed Jenkins using the windows installer, you shouldn't need to do anything else here because the windows installer automatically runs Jenkins as a windows service. 

First, you need to start Jenkins before installing it. This can be done from JNLP, or by running "java -jar jenkins.war".

Now connect to Jenkins by going to the following URL http://<hostname>:8080/
Once Jenkins is started this way, look for the "Install as Windows Service" link in the "Manage Jenkins" page (requires Microsoft .NET framework version 2.0):

NOTE: The "Install as Windows Service" link indicated above will not appear if Jenkins is already running as a service on the machine. You can verifying that Jenkins is running as a service by launching the Services app from the Windows Start Menu and looking for a running service called "jenkins" among the list of all windows services running on the machine.

Clicking this link shows you the installation screen:


Choose the directory where Jenkins shall be installed (directory must already exist. If not create it before hand). This will become JENKINS_HOME and used to store data files and programs alike.
Upon successful completion of the installation, you should see a page asking you to restart Jenkins.


This is to re-launch Jenkins as a newly installed Windows service. When you click yes, you'll be asked to wait until the restart completes:

If a restart fails for some reason, check the output from Jenkins, which is stored in the installation directory that you specified.

For W2K8 R2 users you may need to add C:\Windows\SysWOW64 to the PATH env var.

At this point you can use the service manager to confirm that Jenkins is running as a service.


Install Slave as a Windows service (require .NET 2.0 framework)

Jenkins also allows you to install a slave agent as a Windows service. (See Distributed builds for more about how to do distribute builds in general.)

First, you configure your slave to run as a JNLP slave agent. This should create a JNLP launch icon in the corresponding page, as shown below:


From the slave machine, launch a slave agent. You should see a window like this:


Choose "File" > "Install as Windows Service" from the menu:


Confirm your intention to install as a service. The installation will place the program files to the directory designated as the slave root directory (from the "configure executors" screen.)


Once the installation succeeds, you'll be asked if you'd like to stop the current slave agent and immediately start a slave agent.


When you click "OK", the slave agent window will terminate. The new slave agent runs as a service without showing a window, so head over to the service manager from the control panel and confirm that the slave agent is indeed running as a service:

If the slave is supposed to start desktop applications you have to allow the service to interact with the desktop (Action->Properties->Logon->Allow service to interact with desktop).

Configure Slave Service to Run as Domain User (Windows Server 2008 R2 x64)

Warning: Hudson may reset this setting if it deploys a new Slave at any time.

On Windows Server 2008 R2 x64 to configure the service Jenkins to run as the desired domain user.

On the Jenkins install directory, grant All Privileges to the Jenkins domain user. You may have to delete all old LOG files, hudson-slave.err, hudson-slave.out, hudson-slave.wrapper and redirect for the service to start back up.

Grant read access to the Jenkins user on the following registry key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurePipeServers\winreg

Start the service back up and you should be able to run jobs as the domain user.

Install Slave as a Windows service (cmd version)

In a cmd execute the following command:

sc.exe create "<serviceKey>" start= auto binPath= "<path to jenkins-slave.exe>" DisplayName= "<service display name>"

<serviceKey> is the name of the registry key that will define the service (this will not be displayed)
<service display name> is the label that will identify the service in the service manager interface

Note that one space after the "=" for each option is mandatory.
Also note that this will not assign a description string to the service. This can be added by creating a new String value called Description in the registry, under

Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\<serviceKey>

See the sc.exe reference for information on sc.exe

See also How To Create a User-Defined Service if you want to manually customize your service attributes.

You can also use instsrv instead of sc.exe:

  1. Run path\to\instsrv "Jenkins Slave" path\to\srvany.exe
  2. Run regedit
  3. Create HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Jenkins Slave\Parameters
  4. Add the following registry keys:
    1. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Jenkins Slave\Description="Jenkins Continuous Integration Slave"
    2. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Jenkins Slave\Parameters\AppParameters="-jar path\to\slave.jar -jnlpUrl http://jenkins-master:8080/computer/jenkins-slave/slave-agent.jnlp"
    3. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Jenkins Slave\Parameters\Application="C:\WINDOWS\system32\java.exe"

Launch Java Web Start slave agent via Windows Scheduler

If you are having trouble getting the Java Web Start agent installed as a Windows service an alternative method of starting the service automatically when Windows starts is to use the Windows Scheduler.

Changing the configuration of services

The JVM launch parameters of these Windows services are controlled by an XML file jenkins.xml and jenkins-slave.xml respectively. These files can be found in $JENKINS_HOME and in the slave root directory respectively, after you've install them as Windows services.

The file format should be self-explanatory. Tweak the arguments for example to give JVM a bigger memory.

Stdout and stderr from the service processes go to log files in the same directory.

Uninstallation

To uninstall the jenkins slave service, run jenkins-slave.exe uninstall from the command line.

To uninstall the jenkins service, run jenkins.exe uninstall from the command line.

Troubleshooting

If the slave service doesn't start as intended, check the following locations for more information.

  • Look at the Windows event viewer under the application section for the logging output from Jenkins. This captures the key Windows service events, such as startup and termination
  • Look at the log files in the directory that jenkins.exe resides. They correspond to the standard output and the standard error from the slave process, and often Java stack traces are sent there.
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Nov 07, 2008

    Peter Kahn says:

    If you run into an authentication problem (perhaps because you are using apache-...

    If you run into an authentication problem (perhaps because you are using apache-auth on your SVN server) you can force the service to cache the auth credentials by going to the *script console* and executing some groovy code that auths as the user you'd like to use.

    "cmd /c svn ls \--username builder \--password blah http://svn.host.com/svn/repos".execute()
    
  2. Feb 18, 2009

    Liya says:

    I work with version 1.276 installed on Windows XP and i don't have this option i...

    I work with version 1.276 installed on Windows XP and i don't have this option in the Manage Hudson page..

    VisualStudio 2008 is installed on the machine.

    Do i need to configure anything else?

    1. Feb 10, 2012

      shashank agarwal says:

      Hi Liya Recently I have installed version 1.50 on Win 7 and under Manage Jenkin...

      Hi Liya

      Recently I have installed version 1.50 on Win 7 and under Manage Jenkins I don't see the option "Install as Window service".

      If by now you have some workaround for above fix please do share 

  3. Mar 30, 2009

    gust says:

    I noticed that Hudson slave as a service must be configured Log on as account to...

    I noticed that Hudson slave as a service must be configured Log on as account to get slave's other drives to work. If Local System Account used Hudson job did not find other drives (E.

    Also there must be free space 1Gb available in slave Windows, otherwise connection (master<->slave) won't work. Pls correct me if I am wrong.

    -gust-

  4. Apr 07, 2009

    John Agar says:

    where can i find the hudson.war file for the installation? under download i jus...

    where can i find the hudson.war file for the installation?

    under download i just find a hudson.zip file.

    also, which version should be downloaded? they are all marked as stable? seems quite strange to me.

    1. Apr 21, 2009

      David Dull says:

      All you have to do is change the extension from zip to hpi. Windows is helping y...

      All you have to do is change the extension from zip to hpi. Windows is helping you!

  5. Apr 21, 2009

    David Dull says:

    Is anyone having problems w/ environment variables not matching? (windows XP) I...

    Is anyone having problems w/ environment variables not matching? (windows XP)

    If I go to manage hudson -> system information and display the environment variables the list is incomplete as compared to the list given when I just do a set command from DOS. (what's missing is the embedded compiler license)

    Thank you

  6. Jul 24, 2009

    Carlton Brown says:

    I'm having trouble installing my Hudson slave agent as a service.  Whe...

    I'm having trouble installing my Hudson slave agent as a service.  When i select "File" > "Install as Windows Service" I receive the following error message:

         java.io.IOException: Cannot run program "/hudson-slave.exe" (in directory ""): CreateProcess eror = 267, The directory name is invalid

    Does anyone have any idea what could be causing this?  I have a master running on Ubuntu and two Windows Xp slaves.  The jnlp runs fine from the browser launch, but it won't install as a service.  When I attempt to install it from the command line the service won't start and it gives the error:

         "Could not start the HudsonSlave service on Local Computer.  Error 1053: the service did not respond to the start or control request in a timely fashion."

    Thanks

  7. Aug 19, 2009

    Frank says:

    Is there a way to restart Hudson manually through the user interface? I don't se...

    Is there a way to restart Hudson manually through the user interface? I don't see this anywhere. This would be much nicer than having to kill the process or restart the daemon in Unix.

  8. Aug 24, 2009

    Aditya Kumar Pandey says:

    To install the service, run hudson.exe install from the command line. It works

    To install the service, run hudson.exe install from the command line. It works

    1. Oct 15, 2009

      newguy says:

      Yeah, but before you install the service there is no hudson.exe. That exe file i...

      Yeah, but before you install the service there is no hudson.exe. That exe file is generated by the service.

  9. Feb 12, 2010

    Pradeep Bandi says:

    I am trying to configure Hudson-Slave on a VMWare machine. I was able to run tha...

    I am trying to configure Hudson-Slave on a VMWare machine. I was able to run that as a slave, but I am unable to configure it as “Install as a Windows Service”.  It is throwing following error (Even though it is not installed as a windows service the Hudson master is able to detect it as a slave and I am able to do a build also). I am unable to figure out what that error is for. By the same way, I am able to successfully install the slave as a windows service on a Windows-XP machine or on a Server 2003 machine.  I am thinking that Hudson is unable to create an interface with VMWare to install it as windows service. Can anyone help me out with this issue?

  10. Feb 17, 2010

    Jes Struck says:

    after a have installed the slave service on my windows XP machine i go to Servic...

    after a have installed the slave service on my windows XP machine i go to Services and make service run under a specific userprofile, but after that it seems that the service won´t start... is there anyone that could give me a hint... please

  11. Mar 18, 2010

    Paoli says:

    I have a problem with Hudson in Windows. I've been able to install it as a servi...

    I have a problem with Hudson in Windows. I've been able to install it as a service without a problem and I've executed jobs successfully. The problem is that for one job in particular, I need to use the archive from the Last Successful build, however, the LastSuccessful and LastStable symbolic links are not created. I had already tested hudson under Linux and those symbolic links are created automatically upon executing jobs that are configured to archive the artifacts. I have this setting as well in the windows install, but the symbolic links are never created. I don't know if it's because I'm running on Windows and the creation of these links is simply not possible or maybe I'm missing something.

    Any ideas? Thanks.

  12. Jul 23, 2010

    Rex Morrey says:

    We installed Hudson as a service on a Sun server, but when we try to run a build...

    We installed Hudson as a service on a Sun server, but when we try to run a build on that server we get permission errors when trying to create folders or files or if we try to delete files or folders.  I inserted a "who" command into the script to determine what the username of the process is but nothing was displayed.  Can someone help me figure out how to determine the username the process runs under?

  13. Nov 08, 2010

    Espen Albrektsen says:

    Tried to install a slave on my laptop for local testing of builds, and got the (...

    Tried to install a slave on my laptop for local testing of builds, and got the (to me) strange error message:

     System.Management.ManagementException: Not found
       at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
       at System.Management.ManagementScope.InitializeGuts(Object o)
       at System.Management.ManagementScope.Initialize()
       at System.Management.ManagementScope.Connect()
       at WMI.WmiRoot..ctor(String machineName)
       at WMI.WmiRoot..ctor()
       at winsw.WrapperService.Run(String[] args)
       at winsw.WrapperService.Main(String[] args)
    

    After a little bit of googling - I realized the error is quite clear: System.Management is not found because I have not installed the .Net framework on my machine yet.
    Since hudson is running on Java, it never occured to me that .Net could be required, I am downloading the .Net 4.0 framework now.

    Installing .Net 4.0 does not solve the issue - and that makes sense - we would not get the System.Management.ManagementException unless some parts of the .Net framework was installed.

    This thread indicates I need to rebuild WMI: net.java.dev.hudson.users

    I followed the steps in this guide , and hudson slave now installed successfully on WinXP (32 bit)

    :-)

  14. Jun 02, 2011

    Bruce Boughton says:

    Espen, I too was getting an error from System.Management namespace but didn't f...

    Espen,

    I too was getting an error from System.Management namespace but didn't fancy "fixing" WMI. Instead you can use sc to install the service manually (once you have launched the WebStart program once)

    sc create JenkinsSlave binPath= C:\PathToSlaveHomeDir\jenkins-slave.exe start= auto DisplayName= "Hudson Slave (Jenkins)"
    
  15. Oct 14, 2011

    Akira Shirai says:

    We installed the latest Jenkins (1.434) on our Windows 2008 Server Standard, but...

    We installed the latest Jenkins (1.434) on our Windows 2008 Server Standard, but we don't see "Install as Windows Service" under Manage Jenkins.
    This must be a stupid question but what are we doing wrong?

    1. Feb 10, 2012

      shashank agarwal says:

      Hi Akira I'm also facing the same problem with jenkins.war 1.50 release.  ...

      Hi Akira

      I'm also facing the same problem with jenkins.war 1.50 release. 

      If by now you have found something how to fix it please do share 

      1. Mar 09, 2012

        Akira Shirai says:

        Hi Shashank, No, we still have the same problem with 1.50. Did you figure it ou...

        Hi Shashank,

        No, we still have the same problem with 1.50.
        Did you figure it out?

  16. Oct 21, 2011

    kalpesh soni says:

    If you see System.Management.ManagementException: Not found To get rid of ...

    If you see System.Management.ManagementException: Not found

    To get rid of the service, just use

    sc delete jenkins

  17. May 11, 2012

    chanti vlad says:

    Regarding the cmd part, i have following result on Win Server 2008 64 bit: ...

    Regarding the cmd part, i have following result on Win Server 2008 64 bit:

    [SC] CreateService SUCCESS

    However, if issue right after that a "sc start JenkinsSlave", i get 

    [SC] StartService FAILED 1053:

    The service did not respond to the start or control request in a timely fashion.

    Did someon get that issue too?

    [SC] StartService FAILED 1053:
    The service did not respond to the start or control request in a timely fashion.

  18. Aug 23, 2012

    Torben Vesterager says:

    So - does jenkins-slave.exe work with .NET 3.5 installed? I know it doesn't run...

    So - does jenkins-slave.exe work with .NET 3.5 installed?

    I know it doesn't run with .NET 4.0 only:

  19. Nov 27, 2012

    James Green says:

    Various problems prevented me getting going with a Linux master and Windows 7 sl...

    Various problems prevented me getting going with a Linux master and Windows 7 slave quickly. Here's a summary:

    1. Java Web Start doesn't show the initial dialog.
      Solution: Check the ports for Jenkins. I had a non-standard port and there were "other" areas still configured with the old port. I fixed my issue by reverting the config back to the default port
      Solution: Check the folder specified actually exists and is writable by the JWS user
    2. JWS hangs around in the background
      Solution: Check the log inside your nominated slave install dir. For me, anonymous read access was disabled. I had to allow "Overall > Read" access to anonymous to make things work.
  20. Nov 28, 2012

    Rich Hammett says:

    We're having the same problem described above with a Windows service slave being...

    We're having the same problem described above with a Windows service slave being killed occasionally, but we're using Windows 7, and the instructions above are for older Windows options.  How should I install the slave (to a Linux install of Jenkins) as a Windows service correctly on Windows 7?

  21. Mar 20, 2013

    John Gibson says:

    I started encountering this Error 1053: the service did not respond to the sta...

    I started encountering this

    Error 1053: the service did not respond to the start or control request in a timely fashion.

    while running as a local windows service (no slaves or anything fancy like that) after installing a few plugins.  It turns out that Windows services have a default timeout of 30 seconds when starting up.  I was able to work around the problem by increasing the timeout length to a minute.

    I found the solution here: http://myblog4fun.com/archive/2011/01/31/the-service-did-not-respond-to-the-start-or-control-request-in-a-timely-fashion.aspx.  If that's TL;DR:

    Edit the registry and set HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ServicesPipeTimeout to be a DWORD value in milliseconds.  This is a global change for the timeout for all services.

    Note that the author of that post considers exceeding the 30 second timeout to be a bad design, so perhaps it should be considered a bug when Jenkins takes to long to start/respond to the Windows Service system.

  22. Sep 18, 2013

    Stuart Smith says:

    We have been running Jenkins from the command line for around 6 months, but wish...

    We have been running Jenkins from the command line for around 6 months, but wish to now run the master as a windows service. We run it from a d:/Jenkins dir currently. If I select install as a windows service, and point it to install into that directory, what might the consequences be? Will our jobs all remain, along with all our plug ins and other configuration? Or is the behaviour undocumented?

  23. Nov 20, 2013

    rose red says:

    Hello, I am installing Jenkins 1.540 on windows server standard SP2. I have dow...

    Hello,

    I am installing Jenkins 1.540 on windows server standard SP2. I have downloaded  jenkins1.540.zip which have jenkins-1.540.msi and setup.exe in it. extracted files and when i run setup.exe it goes smooth and at end when in status it says starting jenkins as service through error in below picture. i am logged in as admin to machine. i tried to "run as administrator"  and without it, get same error. any tips please!!

    appreciate your help :-) 

    -Rose

  24. Nov 20, 2013

    rose red says:

    Hello, I am installing Jenkins 1.540 on windows server standard SP2. I have dow...

    Hello,

    I am installing Jenkins 1.540 on windows server standard SP2. I have downloaded  jenkins1.540.zip which have jenkins-1.540.msi and setup.exe in it. extracted files and when i run setup.exe it goes smooth and at end when in status it says starting jenkins as service through error in below picture. i am logged in as admin to machine. i tried to "run as administrator"  and without it, get same error. any tips please!!

    appreciate your help :-) 

    -Rose

    1. Nov 21, 2013

      Eric Anderson says:

      I am having a similar issue - I have attempted to install Jenkins on 3 separate ...

      I am having a similar issue - I have attempted to install Jenkins on 3 separate machines using v. 1.540 both using command line -jar and the Windows installer. Each time Jenkins is able to successfully install but when the browser launches it cannot connect to Jenkins. Also, the Windows service has stopped. After restarting the service and attempting to access Jenkins via http://localhost:8080 through the browser again - the same issue occurs (can't connect via browser- windows service stopped again).

      OS is Win 7 64-bit (I machine was VM, the other two were a laptop and and desktop).

      Windows Event Log:

      Faulting application name: java.exe, version: 7.0.250.17, time stamp: 0x51c4b3fd

      Faulting module name: ntdll.dll, version: 6.1.7601.18247, time stamp: 0x521ea8e7

      Exception code: 0xc0000374

      Fault offset: 0x000ce753

      Faulting process id: 0x2bf0

      Faulting application start time: 0x01cee6b2712f5fc4

      Faulting application path: C:\Program Files (x86)\Jenkins\jre\bin\java.exe

      Faulting module path: C:\Windows\SysWOW64\ntdll.dll

      Any help appreciated - thanks.

  25. Nov 21, 2013

    rose red says:

    In follow up to earlier post. when i try to setup jenkins as windows process fro...

    In follow up to earlier post. when i try to setup jenkins as windows process from manage jenkins i get following error

    ErrorInstalling a service

    [.jenkins] $ F:\Jenkins\Jenkins1\.jenkins\jenkins.exe install
    WMI.WmiException: StatusServiceExists
    at WMI.WmiRoot.BaseHandler.CheckError(ManagementBaseObject result)
    at WMI.WmiRoot.ClassHandler.Invoke(Object proxy, MethodInfo method, Object[] args)
    at WMI.Win32ServicesProxy.Create(String , String , String , ServiceType , ErrorControl , StartMode , Boolean , String[] )
    at winsw.WrapperService.Run(String[] _args)
    at winsw.WrapperService.Main(String[] args).

    any suggestions please !!
    -Rose