使用Winsw的Jenkins Windows从属设置不工作

cngwdvgl  于 2023-02-21  发布在  Jenkins
关注(0)|答案(3)|浏览(212)

使用此信息https://hayato-iriumi.net/2019/05/23/how-to-install-jenkins-slave-as-windows-service/,我们正在Windows服务器上设置Jenkins Slave。Jenkins代理从命令行启动。但当我们从Windows服务启动时,它会给出以下错误消息?如何解决此错误消息?

Service cannot be started. System.IO.InvalidDataException: Attribute <className> is missing in configuration XML
   at winsw.Util.XmlHelper.SingleAttribute[TAttributeType](XmlElement node, String attributeName)
   at winsw.Extensions.WinSWExtensionDescriptor.FromXml(XmlElement node)
   at winsw.Extensions.WinSWExtensionManager.LoadExtension(String id)
   at winsw.Extensions.WinSWExtensionManager.LoadExtensions()
   at winsw.WrapperService.OnStart(String[] args)
   at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)

我们拥有的xml文件

<service>
  <id>JenkinsSlave</id>
  <name>Jenkins agent</name>
  <description>This service runs an agent for Jenkins automation server.</description>
  <executable>c:\java\jdk-11\bin\java.exe</executable>
  <arguments>-Xrs -jar "c:\jenkins\slave.jar" -jnlpUrl https://jenkinsmaster/jenkins/computer/slave01/slave-agent.jnlp -secret a4b5b4ddfd34a016cd3a8eb94cbe8f908613e33a66db5fa6f5f43a080aea3116 -workDir=c:\jenkins</arguments>
  <workingdirectory>c:\jenkins</workingdirectory>
  <logmode>rotate</logmode>
  <onfailure action="restart">
    <download from="https://jenkinsmaster/jenkins/jnlpJars/slave.jar" to="c:\jenkins\slave.jar"> 
        <extensions>
            <extension enabled="false" classname="winsw.Plugins.RunawayProcessKiller.RunawayProcessKillerExtension" id="killOnStartup">
                <pidfile>c:\jenkins\jenkins_agent.pid</pidfile>
                <stoptimeout>5000</stoptimeout>
                <stopparentfirst>false</stopparentfirst>
            </extension>
        </extensions>
    </download>
  </onfailure>
</service>

谢谢

r6l8ljro

r6l8ljro1#

在链接的网页(你的网页显然是基于它的)上显示的示例“Jenkins-Slave.xml”中有一些错误。它的所有元素和属性都以小写命名,但实际上其中一些应该是大小写混合的(从错误消息中可以看出,它没有找到属性className)。
试试这个吧:

<service>
  <id>YourJenkinsSlaveServiceId</id>
  <name>Your Jenkins Slave Service Name</name>
  <description>This service runs an agent for Jenkins automation server.</description>
  <executable>C:\Program Files\Java\JRE8\bin\java.exe</executable>
  <arguments>-Xrs -jar "%BASE%\slave.jar" -jnlpUrl http://YourJenkinsServer:8080/computer/YourNodeName/slave-agent.jnlp -secret YourSecretStringConsistingOfHexadecimalCharacters -workDir=C:\YourNodeWorkDir</arguments>
  <logmode>rotate</logmode>
  <onfailure action="restart" />
  <download from="http://YourJenkinsServer:8080/jnlpJars/agent.jar" to="%BASE%\slave.jar"/>
 <extensions>
    <extension enabled="true" className="winsw.Plugins.RunawayProcessKiller.RunawayProcessKillerExtension" id="killOnStartup">
      <pidfile>%BASE%\jenkins_agent.pid</pidfile>
      <stopTimeout>5000</stopTimeout>
      <stopParentFirst>false</stopParentFirst>
    </extension>
  </extensions>
</service>

这是从一个更详细的解释,如何安装代理作为一个Windows服务,我已经在this answer

5us2dqdw

5us2dqdw2#

I too has the same issue similarly..

System.IO.FileNotFoundException: Unable to locate jenkins.xml file within executable directory or any parents
   at winsw.ServiceDescriptor..ctor()
   at winsw.WrapperService.Run(String[] _args, ServiceDescriptor descriptor)
   at winsw.WrapperService.Main(String[] args)

Solution:
Save your jenkins-agent file as xml format. not just jenkins-agent.xml

we can use notepad++ to save the xml type.
similarly remove .exe at end of jenkins-agent.exe

Hope its useful.... cheers !!
xfb7svmp

xfb7svmp3#

classNamestopTimeoutstopParentFirst不应为小写。

相关问题