-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdd-VstsAgent.ps1
67 lines (51 loc) · 1.74 KB
/
Add-VstsAgent.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
<#
.SYNOPSIS
Add the VSTS agent
.DESCRIPTION
To be called as part of the CustomScriptExtension of an Azure VM
.PARAMETER AccountUrl
URL to the account for the Agent
.PARAMETER PAT
PAT for the user for the Agent
.PARAMETER AdminUser
User name to run the service as domain\user
.PARAMETER AdminUserPwd
Password for AdminUser
.PARAMETER AgentPool
Pool for the agent, defaults to "AgentPool"
#>
param(
[Parameter(Mandatory)]
[string] $LogFile,
[Parameter(Mandatory)]
[string] $AccountUrl,
[Parameter(Mandatory)]
[string] $PAT,
[Parameter(Mandatory)]
[string] $AdminUser,
[Parameter(Mandatory)]
[string] $AdminUserPwd,
[Parameter(Mandatory)]
[string] $AgentPool,
[Parameter(Mandatory)]
[ValidateScript({Test-Path $_ -PathType Container})]
[string] $DownloadFolder
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$Folder = $PWD
Logit "Add-VstsAgent started"
Logit -indent "AccountUrl = $AccountUrl"
Logit -indent "AdminUser = $AdminUser"
Logit -indent "AgentPool = $AgentPool"
Logit -indent "PAT $($PAT[0]+"*"*$PAT.Length)"
Logit -indent "AdminUserPwd $($AdminUserPwd[0]+"*"*$AdminUserPwd.Length)"
Logit -indent "Folder is $Folder"
$fname = (Get-Item (Join-Path $DownloadFolder "vsts-agent*.zip")).FullName
Logit -indent "fname is $fname"
Expand-Archive -Path $fname -DestinationPath $Folder -Force
Logit -indent "$fname expanded into $Folder"
# ok to remove if not there
.\config.cmd remove --unattended --auth pat --token $PAT 2>&1 >> $LogFile
.\config.cmd --unattended --url $AccountUrl --auth pat --token $PAT --pool $AgentPool --agent $env:COMPUTERNAME --windowsLogonAccount $AdminUser --windowsLogonPassword $AdminUserPwd --runAsService 2>&1 >> $LogFile
Logit -indent "config.cmd exited and LASTEXITCODE is $LASTEXITCODE" -LastExit $LASTEXITCODE