-
Notifications
You must be signed in to change notification settings - Fork 47
/
ConfigureASEBuildAgent.ps1
126 lines (109 loc) · 3.58 KB
/
ConfigureASEBuildAgent.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
configuration ConfigureASEBuildAgentDsc
{
param
(
[Parameter(Mandatory)]
[String]$TSUrl,
[Parameter(Mandatory)]
[String]$AgentPool,
[Parameter(Mandatory)]
[String]$PAToken,
[Parameter(Mandatory)]
[String]$AseIp,
[Parameter(Mandatory)]
[String]$AppDns,
[Parameter(Mandatory=$false)]
[String]$VSTSAgentUrl = "https://vstsagentpackage.azureedge.net/agent/2.127.0/vsts-agent-win-x64-2.127.0.zip"
)
Import-DscResource -ModuleName xNetworking, 'PSDesiredStateConfiguration'
$tmp = $AppDns.Split('.')
$OFS='.'
$AppScmDns = $tmp[0] + ".scm." + [String]$tmp[1..$tmp.Count]
Node localhost
{
Script DownloadAgent
{
GetScript = {
return @{ 'Result' = $true }
}
SetScript = {
$agentUrl = $using:VSTSAgentUrl
$agentZip = "$env:TEMP" + "\vsts_agent.zip"
Write-Host "Downloading TFS: $agentUrl"
Invoke-WebRequest -Uri $agentUrl -OutFile $agentZip
}
TestScript = {
$agentZip = "$env:TEMP" + "\vsts_agent.zip"
Test-Path $agentZip
}
}
Script UnzipAgent
{
GetScript = {
return @{ 'Result' = $true }
}
SetScript = {
$agentZip = "$env:TEMP" + "\vsts_agent.zip"
$agentPath = "C:\agent"
If(!(Test-Path $agentPath))
{
New-Item -ItemType Directory -Force -Path $agentPath
}
$shell = New-Object -com shell.application
$zip = $shell.NameSpace($agentZip)
Foreach($item in $zip.items())
{
$shell.Namespace($agentPath).copyhere($item)
}
}
TestScript = {
Test-Path "C:\agent\config.cmd"
}
DependsOn = "[Script]DownloadAgent"
}
Script ConfigAgent
{
GetScript = { return @{ 'Result' = $true }}
SetScript = {
Set-Location "C:\agent"
$tsurl = $using:TSUrl
$tok = $using:PAToken
$pool = $using:AgentPool
$cmd = ".\config.cmd --unattended --runAsService --work _work --url $tsurl --auth pat --token $tok --pool $pool --agent $env:COMPUTERNAME"
Invoke-Expression $cmd | Write-Verbose
}
TestScript = {
Test-Path "C:\agent\.credentials"
}
DependsOn = "[Script]UnzipAgent"
}
xHostsFile HostEntry
{
HostName = $AppDns
IPAddress = $AseIp
Ensure = 'Present'
}
xHostsFile HostScmEntry
{
HostName = $AppScmDns
IPAddress = $AseIp
Ensure = 'Present'
}
Registry StrongCrypto1
{
Ensure = "Present"
Key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319"
ValueName = "SchUseStrongCrypto"
ValueType = "Dword"
ValueData = "00000001"
}
Registry StrongCrypto2
{
Ensure = "Present"
Key = "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\v4.0.30319"
ValueName = "SchUseStrongCrypto"
ValueType = "Dword"
ValueData = "00000001"
}
}
}