Skip to content

Commit 9213344

Browse files
committed
Adds Windows Jenkins Slave update script
1 parent af7f9c2 commit 9213344

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

UpdateJenkinsSlave.ps1

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Schedule with:
2+
# schtasks.exe /create /tn Jenkins-Slave-Update /tr "powershell -NonInteractive -File c:\Tools\UpdateJenkinsSlave.ps1" /sc DAILY /ru Administrator /rp /st 01:00:00
3+
4+
$ErrorActionPreference = "Stop"
5+
6+
$jenkinsBaseUrl = "http://10.73.76.93:8080"
7+
$jenkinsSlaveDir = "c:\Jenkins"
8+
9+
$tmpFile = "$jenkinsSlaveDir\slave.jar.tmp"
10+
$slaveJar = "$jenkinsSlaveDir\slave.jar"
11+
12+
Invoke-WebRequest -Uri "$jenkinsBaseUrl/jnlpJars/slave.jar" -OutFile $tmpFile
13+
14+
$tmpFileHash = (Get-FileHash $tmpFile).Hash
15+
$oldFileHash = (Get-FileHash $slaveJar).Hash
16+
17+
if ($tmpFileHash -ne $oldFileHash) {
18+
echo "Updating $slaveJar"
19+
net stop 'Jenkins Slave'
20+
get-process | where {$_.Name -eq 'java'} | kill
21+
del $slaveJar
22+
move $tmpFile $slaveJar
23+
net start 'Jenkins Slave'
24+
}
25+
else {
26+
echo "No need to update"
27+
del $tmpFile
28+
}
29+

0 commit comments

Comments
 (0)