This repository has been archived by the owner on Jul 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathagent-userscript.ps1
70 lines (59 loc) · 2.8 KB
/
agent-userscript.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
63
64
65
66
67
68
69
70
Param(
[String]$JenkinsMaster
,
[String]$WorkDir
,
[String]$SecretKey
,
[String]$JNLPUrl
,
[String]$JavaBucketPath
,
[String]$WinSwBucketPath
,
[String]$VSBTBucketPath
)
$ErrorActionPreference = "Stop"
function downloadJNLP($JenkinsMaster, $WorkDir) {
New-Item -ItemType directory -Path $WorkDir -Force
$url = "https://$JenkinsMaster/jnlpJars/agent.jar"
$output_file = "$Workdir\agent.jar"
Invoke-WebRequest -Uri "$url" -OutFile "$output_file"
}
function InstallJava($bucketname,$objectname) {
Copy-S3Object -BucketName $bucketname -Key $objectname -LocalFile c:\cfn\scripts\java_install.exe;
c:\cfn\scripts\java_install.exe /s INSTALL_SILENT=1 STATIC=0 AUTO_UPDATE=0 WEB_JAVA=1 WEB_JAVA_SECURITY_LEVEL=H WEB_ANALYTICS=0 EULA=0 REBOOT=0 NOSTARTMENU=0 SPONSORS=0 ;
}
function createJenkinsXML ($JNLPUrl, $secret, $workDir) {
$jenkxmlfile = "$workDir\jenkagent.xml"
"<service>" | Out-File -Encoding Ascii -append $jenkxmlfile
" <id>JenkinsAgent</id>" | Out-File -Encoding Ascii -append $jenkxmlfile
" <name>JenkinsAgent</name>" | Out-File -Encoding Ascii -append $jenkxmlfile
" <description>JenkinsAgent</description>" | Out-File -Encoding Ascii -append $jenkxmlfile
" <env name=`"JENKINS_HOME`" value=`"$workDir`"/>" | Out-File -Encoding Ascii -append $jenkxmlfile
" <executable>java</executable>" | Out-File -Encoding ascii -Append $jenkxmlfile
" <arguments>-Xrs -Xmx256m -jar `"$workDir\agent.jar`" -jnlpUrl $JNLPUrl -secret $secret -workDir `"$workDir`"</arguments>" | Out-File -Encoding ascii -Append $jenkxmlfile
" <logmode>rotate</logmode>" | Out-File -Encoding ascii -Append $jenkxmlfile
"</service>" | Out-File -Encoding ascii -Append $jenkxmlfile
}
function setupServiceWrapper($bucketname,$objectname,$workDir) {
Copy-S3Object -BucketName $bucketname -Key $objectname -LocalFile "$workDir\jenkagent.exe"
$cmd = "$workDir\jenkagent.exe install"
Invoke-Expression $cmd
}
function InstallVSBT($bucketname,$objectname) {
Copy-S3Object -BucketName $bucketname -Key $objectname -LocalFile c:\cfn\scripts\vsbt_install.exe;
c:\cfn\scripts\vsbt_install.exe --quiet | Out-Null
Install-WindowsFeature -Name NET-Framework-Core;
}
downloadJNLP $JenkinsMaster $WorkDir
createJenkinsXML $JNLPUrl $SecretKey $WorkDir
$extra,$mystring = $JavaBucketPath -split("https://s3.[0-9A-za-z.-]+/", 2)
$bucketname,$objectname = $mystring -split ("/", 2)
InstallJava $bucketname $objectname
$extra,$mystring = $VSBTBucketPath -split("https://s3.[0-9A-Za-z.-]+/", 2)
$bucketname,$objectname = $mystring -split ("/", 2)
InstallVSBT $bucketname $objectname
$extra,$mystring = $WinSwBucketPath -split("https://s3.[0-9A-za-z.-]+/", 2)
$bucketname,$objectname = $mystring -split ("/", 2)
setupServiceWrapper $bucketname $objectname $WorkDir