-
Notifications
You must be signed in to change notification settings - Fork 2
/
azure-pipelines.yml
217 lines (189 loc) · 7.65 KB
/
azure-pipelines.yml
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
name: AutomationAnywherePipeline$(Date:yyyyMMdd)$(Rev:.r)
trigger: none
parameters:
- name: BotIds
type: string
displayName: 'Comma separated list of Bot Ids'
- name: IncludePackages
type: boolean
displayName: 'Include packages'
default: false
pr: none
pool:
vmImage: 'windows-latest'
stages:
- stage: Export
displayName: 'Export Bots from Dev Control Room'
variables:
- group: 'AutomationAnywhere.DEV'
jobs:
- job: ExportBots
displayName: 'Authenticate to Dev, Export Bots'
steps:
- task: PowerShell@2
name: Authenticate
displayName: 'Get Dev Authentication Token'
env:
AutomationAnywhere_Username: $(AutomationAnywhere.Username)
AutomationAnywhere_ApiKey: $(AutomationAnywhere.ApiKey)
inputs:
pwsh: true
targetType: 'inline'
script: |
$ErrorActionPreference = "Stop"
$scriptPath = "$(Build.SourcesDirectory)\pipeline\scripts\GetAuthToken.ps1"
Write-Host "Running script: $scriptPath"
$username = "$env:AutomationAnywhere_Username"
$apiKey = "$env:AutomationAnywhere_ApiKey"
$result = & $scriptPath -ControlRoomAPIUrl $(AutomationAnywhere.Url) -Username $username -ApiKey $apiKey
if ($result.Success) {
Write-Host "Access Token to AutomationAnywhere retrieved successfully"
Write-Host "##vso[task.setvariable variable=AccessToken]$($result.AccessToken)"
} else {
Write-Host "##vso[task.complete result=Failed;]DONE"
}
- task: PowerShell@2
name: ExtractBotsInfo
displayName: 'Extract Bots Info'
inputs:
pwsh: true
targetType: 'inline'
script: |
$ErrorActionPreference = "Stop"
$scriptPath = "$(Build.SourcesDirectory)\pipeline\scripts\GetBotsInfo.ps1"
Write-Host "Running script: $scriptPath"
$botIds = ${{ parameters.BotIds }}
if ($botIds -is [array]) {
$botIdsString = $botIds -join ","
} else {
$botIdsString = $botIds
}
$result = & $scriptPath `
-ControlRoomAPIUrl $(AutomationAnywhere.Url) `
-BotIds $botIdsString `
-AccessToken $(AccessToken)
if(!$result.Success) {
Write-Host "##vso[task.complete result=Failed;]DONE"
return
}
Write-Host "Bots info retrieved successfully"
$botsJson = $result.Bots | ConvertTo-Json -Depth 5
Write-Host "botsJson: $botsJson"
$botsJson | Out-File "$(Build.ArtifactStagingDirectory)\Bots_$(Get-Date -Format 'yyyyMMdd_HHmmss').json"
- task: PowerShell@2
name: Export
displayName: 'Export and Download the bot'
inputs:
pwsh: true
targetType: 'inline'
script: |
$ErrorActionPreference = "Stop"
$exportScriptPath = "$(Build.SourcesDirectory)\pipeline\scripts\ExportBots.ps1"
Write-Host "Running export script: $exportScriptPath"
$botIds = ${{ parameters.BotIds }}
if ($botIds -is [array]) {
$botIdsString = $botIds -join ","
} else {
$botIdsString = $botIds
}
$exportResult = & $exportScriptPath `
-ControlRoomAPIUrl $(AutomationAnywhere.Url) `
-BotIds $botIdsString `
-IncludePackages $${{ parameters.IncludePackages }} `
-AccessToken $(AccessToken)
if(!$exportResult.Success) {
Write-Host "##vso[task.complete result=Failed;]DONE"
return
}
$statusScriptPath = "$(Build.SourcesDirectory)\pipeline\scripts\getImportExportStatus.ps1"
Write-Host "Running status script: $statusScriptPath"
$statusResult = & $statusScriptPath -ControlRoomAPIUrl $(AutomationAnywhere.Url) -RequestId $exportResult.RequestId -AccessToken $(AccessToken)
$retryCount = 0
while ($true) {
$retryCount++
if ($statusResult.Status -eq "Completed") {
break;
} elseif ($statusResult.Status -eq "Failed") {
Write-Host "##vso[task.complete result=Failed;]DONE"
return
} else {
Write-Host "Waiting for export to complete..."
Start-Sleep -Seconds 10
$statusResult = & $statusScriptPath -ControlRoomAPIUrl $(AutomationAnywhere.Url) -RequestId $exportResult.RequestId -AccessToken $(AccessToken)
}
if ($retryCount -gt 10) {
Write-Host "##vso[task.complete result=Failed;]DONE"
return
}
}
$downloadFileId = $statusResult.DownloadFileId
$downloadScriptPath = "$(Build.SourcesDirectory)\pipeline\scripts\downloadExportedBots.ps1"
Write-Host "Running download script: $downloadScriptPath"
$downloadResult = & $downloadScriptPath `
-ControlRoomAPIUrl $(AutomationAnywhere.Url) `
-DownloadFileId $downloadFileId `
-PipelineWorkspace $(Build.ArtifactStagingDirectory) `
-AccessToken $(AccessToken)
if ($downloadResult.Success) {
Write-Host "##vso[task.setvariable variable=ArchiveFileId;isOutput=true]$downloadFileId"
Write-Host "##vso[task.setvariable variable=ArchivePassword;isOutput=true]$($exportResult.ArchivePassword)"
} else {
Write-Host "HTTP request failed with status code: $($downloadResponse.StatusCode)"
Write-Host "##vso[task.complete result=Failed;]DONE"
}
- task: PublishBuildArtifacts@1
name: Publish
displayName: 'Publish the exported bot'
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'Bot'
publishLocation: 'Container'
- stage: UAT
displayName: 'Import Bots to UAT Control Room'
dependsOn:
- Export
condition: succeeded()
variables:
- group: 'AutomationAnywhere.UAT'
- name: ArchiveFileId
value: $[ stageDependencies.Export.ExportBots.outputs['Export.ArchiveFileId'] ]
- name: ArchivePassword
value: $[ stageDependencies.Export.ExportBots.outputs['Export.ArchivePassword'] ]
jobs:
- deployment: uat
environment: 'AutomationAnywhere_UAT'
strategy:
runOnce:
deploy:
steps:
- template: 'import.yml'
parameters:
ControlRoomName: 'UAT'
ArchivePath: $(Pipeline.Workspace)\Bot\$(ArchiveFileId).zip
ArchiveName: $(ArchiveFileId).zip
ArchivePassword: $(ArchivePassword)
- stage: PROD
displayName: 'Import Bots to Production Control Room'
dependsOn:
- Export
- UAT
condition: succeeded()
variables:
- group: 'AutomationAnywhere.PROD'
- name: ArchiveFileId
value: $[ stageDependencies.Export.ExportBots.outputs['Export.ArchiveFileId'] ]
- name: ArchivePassword
value: $[ stageDependencies.Export.ExportBots.outputs['Export.ArchivePassword'] ]
jobs:
- deployment: prod
environment: 'AutomationAnywhere_PROD'
strategy:
runOnce:
deploy:
steps:
- template: 'import.yml'
parameters:
ControlRoomName: 'PROD'
ArchivePath: $(Pipeline.Workspace)\Bot\$(ArchiveFileId).zip
ArchiveName: $(ArchiveFileId).zip
ArchivePassword: $(ArchivePassword)