-
Notifications
You must be signed in to change notification settings - Fork 0
/
AzureDeploy.ps1
83 lines (71 loc) · 2.76 KB
/
AzureDeploy.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
# Azure DevOps Variables
$DevOpsOrg = '<DevOpsOrganizationName>'
$DevOpsPAT = '<DevOpsPersonalAccessToken>'
# Azure Resource Variables
$AutomationName = '<AutomationName>'
$AutomationResourceGroup = '<AutomationResourceGroup>'
$DotNetAgentVMName = '<DotNetAgentVMName>'
$NodeJsAgentVMName = '<NodeJsAgentVMName>'
$AzureVMResourceGroup = '<AzureVMResourceGroup>'
$AzureVMLocation = '<AzureVMLocation>'
# DSC Configuration Path
$dscConfigPath = "$PSScriptRoot\SelfHostedAgent.ps1"
# Login to Azure
Connect-AzAccount
# Create Automation Variable Asset to store PAT.
New-AzAutomationVariable -ResourceGroupName $AutomationResourceGroup `
–AutomationAccountName $AutomationName `
–Name 'DevOpsPersonalAccessToken' `
–Encrypted $true –Value $DevOpsPAT
# Import the DSC configuration
Import-AzAutomationDscConfiguration -ResourceGroupName $AutomationResourceGroup `
–AutomationAccountName $AutomationName `
-SourcePath $dscConfigPath -Force -Published
# Compile the DSC Configuration
$Parameters = @{
'DevOpsOrganizationName' = $DevOpsOrg
}
$ConfigData = @{
AllNodes = @(
@{
NodeName = 'BuildAgents.DotNetAgent'
AgentName = 'DotNetAgent'
AgentPoolName = 'BuildAgents'
},
@{
NodeName = 'BuildAgents.NodeJsAgent'
AgentName = 'NodeJsAgent'
AgentPoolName = 'BuildAgents'
IncludeNodeJs = $true
}
)
}
Start-AzAutomationDscCompilationJob -ResourceGroupName $AutomationResourceGroup `
-AutomationAccountName $AutomationName `
-ConfigurationName 'SelfHostedAgent' `
-Parameters $Parameters `
-ConfigurationData $ConfigData
Get-AzAutomationDscNodeConfiguration -ResourceGroupName $AutomationResourceGroup `
-AutomationAccountName $AutomationName
# Onboard the node to Automation DSC
Register-AzAutomationDscNode -ResourceGroupName $AutomationResourceGroup `
-AutomationAccountName $AutomationName `
-AzureVMName $DotNetAgentVMName `
-AzureVMResourceGroup $AzureVMResourceGroup `
-AzureVMLocation $AzureVMLocation `
-NodeConfigurationName 'SelfHostedAgent.BuildAgents.DotNetAgent' `
-ConfigurationMode 'ApplyAndMonitor' `
-ConfigurationModeFrequencyMins 15 `
-RefreshFrequencyMins 30 `
-RebootNodeIfNeeded $true
# Onboard the node to Automation DSC
Register-AzAutomationDscNode -ResourceGroupName $AutomationResourceGroup `
-AutomationAccountName $AutomationName `
-AzureVMName $NodeJsAgentVMName `
-AzureVMResourceGroup $AzureVMResourceGroup `
-AzureVMLocation $AzureVMLocation `
-NodeConfigurationName 'SelfHostedAgent.BuildAgents.NodeJsAgent' `
-ConfigurationMode 'ApplyAndMonitor' `
-ConfigurationModeFrequencyMins 15 `
-RefreshFrequencyMins 30 `
-RebootNodeIfNeeded $true