supereagle / experiences

Summary of practical experience in work.
2 stars 0 forks source link

Windows agents automatically connect to Jenkins master after restart #26

Closed supereagle closed 7 years ago

supereagle commented 7 years ago

Background

Unix agents are launched via SSH, they can completely controlled by Jenkins master. If config their availability as Keep this agent online as much as possible, they can automatically connect to Jenkins master after restart. But it is different for Windows agents, they are usually launched via java web start through JNLP protocol. This requires the Windows agents to actively open a JNLP file to establish a TCP connection to the Jenkins master. After Windows agents restart, they are offline and needed to be manually launched via java web start, which is not automatical enough.

Solution

Create the automatical connection script agent.bat in startup folder through Win -> All Programs -> Startup, this folder is always like C:\Users\robin.yue\AppData\Roaming\Microsoft\Windows\Start Menu\Programs. The content of the script agent.bat:

start /b java -jar D:\jenkins\slave.jar -jnlpUrl http://jenkins-master.vclound.com:8080/computer/test-slave/slave-agent.jnlp -secret 0439590ddfb022a84fde1a1ceb55953300db165ce0fb13ec6b5de908e365cc3b

There are two ways to launch Windows agents:

The script agent.bat uses the second way, and is added into the startup to automatically run this command after restart.