-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathjenkins-agent.ps1
62 lines (51 loc) · 2.02 KB
/
jenkins-agent.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
param ([string] $workdir,
[string] $jenkins,
[string] $user,
[string] $password,
[bool] $ignore_ssl_errors=$false)
. C:\Windows\Temp\scripts\ps_support.ps1
Write-Host "Setting up Jenkins agent"
& choco.exe install -y openjdk11
CheckLastExitCode
if (-Not (Test-Path $workdir)) {
New-Item -Type directory $workdir
}
Add-MpPreference -ExclusionPath $workdir
CheckLastExitCode
if ($ignore_ssl_errors) {
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
}
Invoke-WebRequest -Uri "https://${jenkins}/jnlpJars/agent.jar" -Outfile "${workdir}/agent.jar"
CheckLastExitCode
Write-Host "Installing vswhere.exe to used by build steps"
& choco.exe install -y vswhere
CheckLastExitCode
Write-Host "Configuring jenkins agent to launch at boot time"
& choco.exe install -y nssm
CheckLastExitCode
& nssm.exe install jenkins-agent java
CheckLastExitCode
& nssm.exe set jenkins-agent AppParameters "-jar agent.jar -jnlpUrl https://${jenkins}/computer/DUMMYAGENT/jenkins-agent.jnlp -secret DUMMYSECRET -workDir $workdir"
& nssm.exe set jenkins-agent AppDirectory $workdir
& nssm.exe set jenkins-agent AppExit Default Restart
& nssm.exe set jenkins-agent AppStdout "${workdir}/agent-service.log"
& nssm.exe set jenkins-agent AppStderr "${workdir}/agent-service.log"
& nssm.exe set jenkins-agent AppRotateFiles 1
& nssm.exe set jenkins-agent AppRotateBytes 1073741824
& nssm.exe set jenkins-agent DisplayName jenkins-agent
& nssm.exe set jenkins-agent ObjectName ".\${user}" "${password}"
& nssm.exe set jenkins-agent Start SERVICE_AUTO_START
& nssm.exe set jenkins-agent Type SERVICE_WIN32_OWN_PROCESS
Start-Service jenkins-agent
CheckLastExitCode