3

Using this info https://hayato-iriumi.net/2019/05/23/how-to-install-jenkins-slave-as-windows-service/ we are setting up the Jenkins Slave on Windows server. Jenkins agent start from command line. but when we start from Windows service, its giving below error message? How to resolve this error message?

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 file we have

<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>

Thanks

sfgroups
  • 14,561
  • 19
  • 83
  • 153

1 Answers1

2

There are some errors in the sample "Jenkins-Slave.xml" that is presented at the linked web page (which yours is apparently based on). It has all elements and attributes named in lowercase, but actually some of them should be mixed case (as can be seen by the error message that it doesn't find attribute className).

Try this one instead:

<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>

This is from a more detailed explanation of how to install an agent as a Windows service which I have given in this answer.

zett42
  • 14,113
  • 3
  • 17
  • 55