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.

Installing Jenkins as a Windows service的更多相关文章

  1. Install Jenkins Slave as Windows Service

    https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+as+a+Windows+service SC 直接创建windows s ...

  2. Jenkins搭建windows service自动编译发布环境

    类库项目(Task)部署 前面搭建了Web站点的环境,类库项目发布不同于站点项目,它只需要将MSBuild编译出来的dll复制到目标服务器上即可,而不需要通过Web Deploy,下面来说一下如何发布 ...

  3. [转]Installing SharePoint 2013 on Windows Server 2012 R2

    转自:http://www.avivroth.com/2013/07/09/installing-sharepoint-2013-on-windows-server-2012-r2-preview/ ...

  4. 使用BAT安装 Windows Service

    脚本如下: @echo off @setlocal enableextensions @cd /d "%~dp0" set InstallPath=C:\DBoxService\S ...

  5. A basic Windows service in C++ (CppWindowsService)

    A basic Windows service in C++ (CppWindowsService) This code sample demonstrates creating a basic Wi ...

  6. 使用Jenkins自动发布Windows服务项目

    不同于发布Web项目,自动发布Windows服务项目需要解决以下几个问题: 如何远程停止和开启服务?需要在发布前停止服务,在发布完成后开启服务. 如何上传编译文件到目标服务器? 问题1:如何远程停止和 ...

  7. .Net 持续集成 —— windows service

    上一篇讲了 Jenkins+WebDeploy+IIS完成 web项目部署,这篇继续讲windows service的部署. windows service 一般用于自动任务,定时完成某些操作.本文自 ...

  8. Multiple Instance .NET Windows Service

    It's not readily apparent how to install a Windows Service multiple times on a single machine. At fi ...

  9. 在windows service中启动类型“Automatic” 和 “Automatic (Delayed start)” 有何不同?

    问题: When installing Windows services there are two options for automatically starting a Windows serv ...

随机推荐

  1. Unity shader学习之逐像素漫反射光照模型

    shader如下: Shader "Custom/Diffuse Fragment-Level" { Properties { _Diffuse (,,,) } SubShader ...

  2. Support For C++11/14/17 Features (Modern C++)

    Visual Studio编译器对 C++11 特性的支持 具体参考网址:https://msdn.microsoft.com/en-us/library/hh567368.aspx 截至目前为止,V ...

  3. 08 集合[11,22,33,44,55,66,77,88,99],将所有<66的值保存至字典的第一个key中,将所有>=66的值保存至字典的第二个key中。即:{'k1':<66的所有值,'k2':>=66的所有值}

    li = [11,22,33,44,55,66,77,88,99]dict = {'k1':[],'k2':[]}for i in li:    if i < 66:        dict[& ...

  4. 【转】robotFramework 与testlink集成

    场景: robotframework 执行完用例之后,将执行结果报至testlink. 方案1: 通过TestLink-API-Python-client中的RF关键字 每条用例执行完成之后根据状态进 ...

  5. Differencia (归并树)

    归并树,与我们原学过的归并排序是一样的原理,但是在那个的基础上进行扩展应用.首先每个节点储存了它每个节点所代表的点的有序序列,还有就是每个点里面包含的所有的b[i]在左右子树的排名辅助更新数据,还有一 ...

  6. QDialog 使用Demo

    [1].pro QT += core gui greaterThan(QT_MAJOR_VERSION, ): QT += widgets TARGET = TestDialog TEMPLATE = ...

  7. python mmap对象

    ----使用内存映射的原因 为了随机访问文件的内容,使用mmap将文件映射到内存中是一个高效和优雅的方法.例如,无需打开一个文件并执行大量的seek(),read(),write()调用,只需要简单的 ...

  8. 设计模式之Prototype(原型)(转)

    定义: 用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象. Prototype模式允许一个对象再创建另外一个可定制的对象,根本无需知道任何如何创建的细节,工作原理是:通过将一个原型对象传 ...

  9. linux常用命令:ls命令

    ls命令是linux下最常用的命令.ls命令就是list的缩写,缺省下ls用来打印出当前目录的清单,如果ls指定其他目录那么就会显示指定目录里的文件及文件夹清单. 通过ls 命令不仅可以查看linux ...

  10. 20165215 2017-2018-2 《Java程序设计》第九周学习总结

    20165215 2017-2018-2 <Java程序设计>第九周学习总结 教材学习内容总结 URL类 URL 类是 java.net 包中的一个重要的类,使用 URL 创建对象的应用程 ...