从命令行运行Jenkins与作为Windows服务运行 [英] Running Jenkins from command line vs as Windows service

查看:693
本文介绍了从命令行运行Jenkins与作为Windows服务运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个非常奇怪的问题.我需要在我的Jenkins中配置代理,以便能够在其中一项作业中访问SVN存储库.我这样做有两种方式:

I ran into a very strange issue. I need to configure proxy in my Jenkins to be able to access SVN repository in one of the jobs. I have done so in 2 ways:

  1. 使用必需的参数从命令行启动Jenkins
  2. jenkins.xml文件中定义参数时,将Jenkins作为Windows服务启动.
  1. Started Jenkins from command line with the required arguments
  2. Started Jenkins as Windows service while the arguments are defined in the jenkins.xml file.

从命令行开始:

C:\>java -DJENKINS_HOME="C:\.jenkins" -Dhudson.model.DirectoryBrowserSupport.CSP
="`script-src 'unsafe-inline';`" -Dhttp.proxyHost=localhost -Dhttp.proxyPort=312
8 -Dhttps.proxyHost=localhost -Dhttps.proxyPort=3128 -jar %JENKINS_HOME%\jenkins
.war

从服务开始(下面是jenkins.xml内容):

<executable>java</executable>
<arguments>-DJENKINS_HOME="C:\.jenkins" -Dhudson.model.DirectoryBrowserSupport.CSP="`script-src 'unsafe-inline';`" -Dhttp.proxyHost=localhost -Dhttp.proxyPort=3128 -Dhttps.proxyHost=localhost -Dhttps.proxyPort=3128 -jar "%JENKINS_HOME%\jenkins.war"</arguments>

所以完全一样.但是问题是,当我使用命令行启动Jenkins时,代理可以正常工作.但是,当我将Jenkins作为服务启动时,无法访问(通过代理)存储库,并且出现以下错误消息:

So that's exactly the same. The issue however is that when I am using command line to start Jenkins, proxying works fine. But when I start Jenkins as service, the repo (through the proxy) cannot be accessed and I get this error message:

请注意,如果我在系统信息"部分中查看系统属性",则在两种情况下代理参数都将显示为相同,因此配置将被正确应用:

Please note that if I look at the System Properties in System Information section, the proxy parameters appear the same in both cases so the configuration is being applied properly:

显然,Jenkins的启动方式有所不同,具体取决于启动方式(命令行或Windows服务).加强这一假设的是,我看到仅当我将Jenkins作为服务启动时才写入某些日志文件,而当我从命令行启动它时却没有写入.我正在谈论这些日志文件:

Apparently there is a difference in how Jenkins starts up depending on how it was started (command line or windows service). What reinforces this assumption is that I see that some log files are only being written when I start Jenkins as a service but not when I start it from command line. I am talking about these log files:

jenkins.wrapper.log
jenkins.out.log

要像从命令行启动Jenkins一样获得与服务相同的结果,我需要做些什么?我缺少什么配置?

What do I need to do differently to get the same result from Jenkins as service as I do when I start it from command line? What configuration am I missing?

推荐答案

Jenkins作为Windows服务不是在当前用户下运行,而是在本地系统帐户.

Jenkins as a Windows service doesn't run under your current user but under the LocalSystem Account by default.

请参见 MSDN:将LocalSystem帐户用作服务登录帐户.

这篇关于从命令行运行Jenkins与作为Windows服务运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆