Install Jenkins as a Windows service at a command prompt

I searched a lot on Google on how to install the service on the command line (therefore without manual interaction), but I was stuck on how to get jenkins-slave.exe

I found this instruction https://wiki.jenkins.io/display/JENKINS/Installing+Jenkins+as+a+Windows+service but I cannot figure out how to get the executable. I downloaded and launched slave.jar with the right key, which connects the slave, but exe is not generated.

I found this page https://github.com/kohsuke/winsw/blob/master/doc/installation.md#winsw-installation-guide to install it manually, but it sounds like a newly invented wheel when the can can do it. In addition, there is a risk that WinSW.exe is different and not updated by the plugin (I saw in it some automatic update code).

So, is it possible to download jenkins-slave.exe or generate it? or is there a way to run "Install as a Service" on the command line from slave.jar?

+4
source share
2 answers

To answer my own question by contacting the plugin developers:

exe Jenkins , slave.jar . , URL- ( ), .

Worm Service: https://github.com/kohsuke/winsw, .

, WinSW XML, GitHub https://github.com/jenkinsci/windows-slave-installer-module. .

, exe, Jenkins , . jenkins-slave.exe install.

:

  • JNLP- Jenkins ( Node), , . java -jar slave.jar -jnlpUrl http://jenkins...
  • slave.jar Jenkins ( JNLP)
  • , . http://repo.jenkins-ci.org/public/com/sun/winsw/winsw/2.1.0/winsw-2.1.0-bin.exe
  • XML, ( - winsw)
  • XML ( )
  • jenkins-slave.exe install
+4

" " slave.jar?

jenkins-slave.exe, script, , Jenkins, java -jar slave.jar , Jenkins node .

slave.jar , Windows:

curl -o slave.jar https://your.server/jenkins/jnlpJars/slave.jar

jenkins-slave.exe, script, Windows, nssm

script agent.bat:

set PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0
set PATH=D:\Tools\SonarRunner\bin;%PATH%
set M2_HOME=D:\Tools\apache-maven-3.5.0
set PATH=%M2_HOME%\bin;%PATH%
set PATH=D:\Tools\apache-ant-1.9.3\bin;%PATH%
set GH=D:\Tools\Git
set PATH=%GH%\bin;%GH%\usr\bin;%GH%\mingw64\bin;%PATH%
set PATH=%JAVA_HOME%\bin;%PATH%

set WORKSPACE_FOLDER=D:\Jenkins\workspace
set GIT_WORKSPACE_FOLDER=D:\Jenkins\workspace

java -Xmx768m -jar slave.jar -jnlpUrl https://your.server/jenkins/computer/<SlaveName>/slave-agent.jnlp -secret 87ef3d...

, script Windows, :

runas /user:<domain>\<jenkinsUser> cmd ( enter `jenkinsUser` Windows password )

D:\Tools\nssm-2.24\win64\nssm.exe install <SlaveName> D:\Jenkins\agent.bat

Windows:

sc config <SlaveName> obj= <domain>\<jenkinsUsers> password= <jenkinsUser password>
sc config <SlaveName> start= auto

: . Chocolatey - , Windows.


, -API groovy script, Jenkins node/slave JnlpMac .
. script .
groovy script ( Jenkins 2.46 ), :

echo 'println jenkins.model.Jenkins.instance.nodesObject.getNode("my-agent")?.computer?.jnlpMac' \
  | java -jar ~/Downloads/jenkins-cli.jar -s https://jenkins/ groovy =
0

Source: https://habr.com/ru/post/1680088/


All Articles