使用这个 Windows 服务包装器也可以:
https://github.com/winsw/winsw
按照他们的安装,但你应该用你想要的配置更新xml,确保删除xml中路径中的所有"并在jenkins master中禁用websockets代理配置页面:
一步一步:
从https://github.com/winsw/winsw/releases下载exe:WinSW-x64.exe
在代理上创建您的工作区目录并将其粘贴到那里,将 WinSW-x64.exe 重命名为 jenkins-slave.exe
在那里复制你的 jenkins-slave.xml,它应该看起来像:
<service>
<id>jenkins</id>
<name>Jenkins</name>
<description>This service runs Jenkins continuous integration system.</description>
<env name="JENKINS_HOME" value="%BASE%"/>
<executable>C:\Program Files\RedHat\java-1.8.0-openjdk-1.8.0.275-1\jre\bin\java.exe</executable>
<arguments>-jar %BASE%\slave.jar -jnlpUrl https://<your_jenkins>.jenkins.bshg.com/computer/RBGWCW0281/jenkins-agent.jnlp -secret <your_secret> -workDir C:\<workspace-dir>\ -noCertificateCheck</arguments>
<logmode>rotate</logmode>
<onfailure action="restart" />
<delayedAutoStart/>
<!--
If uncommented, download the Remoting version provided by the Jenkins master.
Enabling for HTTP implies security risks (e.g. replacement of JAR via DNS poisoning). Use on your own risk.
NOTE: This option may fail to work correctly (e.g. if Jenkins is located behind HTTPS with untrusted certificate).
In such case the old agent version will be used; you can replace slave.jar manually or to specify another download URL.
-->
<download from="https://<your_jenkins>.jenkins.bshg.com/jnlpJars/slave.jar" to="%BASE%\slave.jar"/>
<!--
In the case WinSW gets terminated and leaks the process, we want to abort
these runaway JAR processes on startup to prevent "Slave is already connected errors" (JENKINS-28492).
-->
<extensions>
<!-- This is a sample configuration for the RunawayProcessKiller extension. -->
<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>
使用选项delayed Auto start,保证所有网络服务都启动,保证jenkins connect不会失败。
我建议使用注册表项让服务有更多时间启动:
插入注册表项,让服务有更多时间启动:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\]
"ServicesPipeTimeout"=dword:0001d4c0
您可以在这里查看详细信息:https://serverfault.com/questions/622432/how-do-i-increase-windows-service-startup-timeout
最后,我建议至少每周自动启动一次 jenkins。有一个计划任务:
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2020-04-30T12:47:51.8471206</Date>
<Author>Domain/User</Author>
<Description>Some Comment</Description>
<URI>\CI-Restart</URI>
</RegistrationInfo>
<Triggers>
<CalendarTrigger>
<StartBoundary>2020-05-01T01:00:00</StartBoundary>
<Enabled>true</Enabled>
<ScheduleByDay>
<DaysInterval>1</DaysInterval>
</ScheduleByDay>
</CalendarTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>whatever</UserId>
<LogonType>Password</LogonType>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>shutdown</Command>
<Arguments>/r /f /t 10 /d p:2:3 /c "CI-reconnect"</Arguments>
</Exec>
</Actions>
</Task>
现在做(具有管理员权限)
- jenkins-slave.exe 安装
- jenkins-slave.exe 启动
您的 Jenkins 将永远运行!