-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathRunPipeline.ps1
569 lines (526 loc) · 26.2 KB
/
RunPipeline.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
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
Param(
[Parameter(HelpMessage = "The GitHub token running the action", Mandatory = $false)]
[string] $token,
[Parameter(HelpMessage = "ArtifactUrl to use for the build", Mandatory = $false)]
[string] $artifact = "",
[Parameter(HelpMessage = "Project folder", Mandatory = $false)]
[string] $project = "",
[Parameter(HelpMessage = "Specifies a mode to use for the build steps", Mandatory = $false)]
[string] $buildMode = 'Default',
[Parameter(HelpMessage = "A JSON-formatted list of apps to install", Mandatory = $false)]
[string] $installAppsJson = '[]',
[Parameter(HelpMessage = "A JSON-formatted list of test apps to install", Mandatory = $false)]
[string] $installTestAppsJson = '[]',
[Parameter(HelpMessage = "RunId of the baseline workflow run", Mandatory = $false)]
[string] $baselineWorkflowRunId = '0',
[Parameter(HelpMessage = "SHA of the baseline workflow run", Mandatory = $false)]
[string] $baselineWorkflowSHA = ''
)
$containerBaseFolder = $null
$projectPath = $null
try {
. (Join-Path -Path $PSScriptRoot -ChildPath "..\AL-Go-Helper.ps1" -Resolve)
Import-Module (Join-Path $PSScriptRoot '..\TelemetryHelper.psm1' -Resolve)
DownloadAndImportBcContainerHelper
Import-Module (Join-Path -Path $PSScriptRoot -ChildPath "..\DetermineProjectsToBuild\DetermineProjectsToBuild.psm1" -Resolve) -DisableNameChecking
if ($isWindows) {
# Pull docker image in the background
$genericImageName = Get-BestGenericImageName
Start-Job -ScriptBlock {
docker pull --quiet $using:genericImageName
} | Out-Null
}
$containerName = GetContainerName($project)
$ap = "$ENV:GITHUB_ACTION_PATH".Split('\')
$branch = $ap[$ap.Count-2]
$owner = $ap[$ap.Count-4]
if ($owner -ne "microsoft") {
$verstr = "dev"
}
else {
$verstr = $branch
}
$runAlPipelineParams = @{
"sourceRepositoryUrl" = "$ENV:GITHUB_SERVER_URL/$ENV:GITHUB_REPOSITORY"
"sourceCommit" = $ENV:GITHUB_SHA
"buildBy" = "AL-Go for GitHub,$verstr"
"buildUrl" = "$ENV:GITHUB_SERVER_URL/$ENV:GITHUB_REPOSITORY/actions/runs/$ENV:GITHUB_RUN_ID"
}
if ($project -eq ".") { $project = "" }
$baseFolder = $ENV:GITHUB_WORKSPACE
if ($bcContainerHelperConfig.useVolumes -and $bcContainerHelperConfig.hostHelperFolder -eq "HostHelperFolder") {
$allVolumes = "{$(((docker volume ls --format "'{{.Name}}': '{{.Mountpoint}}'") -join ",").Replace('\','\\').Replace("'",'"'))}" | ConvertFrom-Json | ConvertTo-HashTable
$containerBaseFolder = Join-Path $allVolumes.hostHelperFolder $containerName
if (Test-Path $containerBaseFolder) {
Remove-Item -Path $containerBaseFolder -Recurse -Force
}
Write-Host "Creating temp folder"
New-Item -Path $containerBaseFolder -ItemType Directory | Out-Null
Copy-Item -Path $ENV:GITHUB_WORKSPACE -Destination $containerBaseFolder -Recurse -Force
$baseFolder = Join-Path $containerBaseFolder (Get-Item -Path $ENV:GITHUB_WORKSPACE).BaseName
}
$projectPath = Join-Path $baseFolder $project
$sharedFolder = ""
if ($project) {
$sharedFolder = $baseFolder
}
$workflowName = "$env:GITHUB_WORKFLOW".Trim()
Write-Host "use settings and secrets"
$settings = $env:Settings | ConvertFrom-Json | ConvertTo-HashTable
# ENV:Secrets is not set when running Pull_Request trigger
if ($env:Secrets) {
$secrets = $env:Secrets | ConvertFrom-Json | ConvertTo-HashTable
}
else {
$secrets = @{}
}
$appBuild = $settings.appBuild
$appRevision = $settings.appRevision
'licenseFileUrl','codeSignCertificateUrl','*codeSignCertificatePassword','keyVaultCertificateUrl','*keyVaultCertificatePassword','keyVaultClientId','gitHubPackagesContext','applicationInsightsConnectionString' | ForEach-Object {
# Secrets might not be read during Pull Request runs
if ($secrets.Keys -contains $_) {
$value = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($secrets."$_"))
}
else {
$value = ""
}
# Secrets preceded by an asterisk are returned encrypted.
# Variable name should not include the asterisk
Set-Variable -Name $_.TrimStart('*') -Value $value
}
$analyzeRepoParams = @{}
if ($artifact) {
# Avoid checking the artifact setting in AnalyzeRepo if we have an artifactUrl
$settings.artifact = $artifact
$gitHubHostedRunner = $settings.gitHubRunner -like "windows-*" -or $settings.gitHubRunner -like "ubuntu-*"
if ($gitHubHostedRunner -and $settings.useCompilerFolder) {
# If we are running GitHub hosted agents and UseCompilerFolder is set (and we have an artifactUrl), we need to set the artifactCachePath
$runAlPipelineParams += @{
"artifactCachePath" = Join-Path $ENV:GITHUB_WORKSPACE ".artifactcache"
}
$analyzeRepoParams += @{
"doNotCheckArtifactSetting" = $true
}
}
}
$settings = AnalyzeRepo -settings $settings -baseFolder $baseFolder -project $project @analyzeRepoParams
$settings = CheckAppDependencyProbingPaths -settings $settings -token $token -baseFolder $baseFolder -project $project
if ((-not $settings.appFolders) -and (-not $settings.testFolders) -and (-not $settings.bcptTestFolders)) {
Write-Host "Repository is empty, exiting"
exit
}
$buildArtifactFolder = Join-Path $projectPath ".buildartifacts"
New-Item $buildArtifactFolder -ItemType Directory | Out-Null
$downloadedAppsByType = @()
if ($baselineWorkflowSHA -and $baselineWorkflowRunId -ne '0' -and $settings.incrementalBuilds.mode -eq 'modifiedApps') {
# Incremental builds are enabled and we are only building modified apps
try {
$modifiedFiles = Get-ModifiedFiles -baselineSHA $baselineWorkflowSHA
OutputMessageAndArray -message "Modified files" -arrayOfStrings $modifiedFiles
$buildAll = Get-BuildAllApps -baseFolder $baseFolder -project $project -modifiedFiles $modifiedFiles
}
catch {
OutputNotice -message "Failed to calculate modified files since $baselineWorkflowSHA, building all apps"
$buildAll = $true
}
if (!$buildAll) {
Write-Host "Get unmodified apps from baseline workflow run"
# Downloaded apps are placed in the build artifacts folder, which is detected by Run-AlPipeline, meaning only non-downloaded apps are built
$downloadedAppsByType = Get-UnmodifiedAppsFromBaselineWorkflowRun `
-token $token `
-settings $settings `
-baseFolder $baseFolder `
-project $project `
-baselineWorkflowRunId $baselineWorkflowRunId `
-modifiedFiles $modifiedFiles `
-buildArtifactFolder $buildArtifactFolder `
-buildMode $buildMode `
-projectPath $projectPath
}
}
if ($bcContainerHelperConfig.ContainsKey('TrustedNuGetFeeds')) {
Write-Host "Reading TrustedNuGetFeeds"
foreach($trustedNuGetFeed in $bcContainerHelperConfig.TrustedNuGetFeeds) {
if ($trustedNuGetFeed.PSObject.Properties.Name -eq 'Token') {
if ($trustedNuGetFeed.Token -ne '') {
OutputWarning -message "Auth token for NuGet feed is defined in settings. This is not recommended. Use a secret instead and specify the secret name in the AuthTokenSecret property"
}
}
else {
$trustedNuGetFeed | Add-Member -MemberType NoteProperty -Name 'Token' -Value ''
}
if ($trustedNuGetFeed.PSObject.Properties.Name -eq 'AuthTokenSecret' -and $trustedNuGetFeed.AuthTokenSecret) {
$authTokenSecret = $trustedNuGetFeed.AuthTokenSecret
if ($secrets.Keys -notcontains $authTokenSecret) {
OutputWarning -message "Secret $authTokenSecret needed for trusted NuGetFeeds cannot be found"
}
else {
$authToken = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($secrets."$authTokenSecret"))
$trustedNuGetFeed.Token = GetAccessToken -token $authToken -repositories @() -permissions @{"packages"="read";"metadata"="read"}
}
}
}
}
else {
$bcContainerHelperConfig.TrustedNuGetFeeds = @()
}
if ($settings.trustMicrosoftNuGetFeeds) {
$bcContainerHelperConfig.TrustedNuGetFeeds += @([PSCustomObject]@{
"url" = "https://dynamicssmb2.pkgs.visualstudio.com/DynamicsBCPublicFeeds/_packaging/AppSourceSymbols/nuget/v3/index.json"
"token" = ''
})
}
$install = @{
"Apps" = $settings.installApps + @($installAppsJson | ConvertFrom-Json)
"TestApps" = $settings.installTestApps + @($installTestAppsJson | ConvertFrom-Json)
}
# Replace secret names in install.apps and install.testApps
foreach($list in @('Apps','TestApps')) {
$install."$list" = @($install."$list" | ForEach-Object {
$pattern = '.*(\$\{\{\s*([^}]+?)\s*\}\}).*'
$url = $_
if ($url -match $pattern) {
$finalUrl = $url.Replace($matches[1],[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($secrets."$($matches[2])")))
}
else {
$finalUrl = $url
}
# Check validity of URL
if ($finalUrl -like 'http*://*') {
try {
Invoke-WebRequest -Method Head -UseBasicParsing -Uri $finalUrl | Out-Null
}
catch {
throw "Setting: install$($list) contains an inaccessible URL: $($url). Error was: $($_.Exception.Message)"
}
}
return $finalUrl
})
}
# Analyze app.json version dependencies before launching pipeline
# Analyze InstallApps and InstallTestApps before launching pipeline
# Check if codeSignCertificateUrl+Password is used (and defined)
if (!$settings.doNotSignApps -and $codeSignCertificateUrl -and $codeSignCertificatePassword -and !$settings.keyVaultCodesignCertificateName) {
OutputWarning -message "Using the legacy CodeSignCertificateUrl and CodeSignCertificatePassword parameters. Consider using the new Azure Keyvault signing instead. Go to https://aka.ms/ALGoSettings#keyVaultCodesignCertificateName to find out more"
$runAlPipelineParams += @{
"CodeSignCertPfxFile" = $codeSignCertificateUrl
"CodeSignCertPfxPassword" = ConvertTo-SecureString -string $codeSignCertificatePassword
}
}
if ($applicationInsightsConnectionString) {
$runAlPipelineParams += @{
"applicationInsightsConnectionString" = $applicationInsightsConnectionString
}
}
if ($keyVaultCertificateUrl -and $keyVaultCertificatePassword -and $keyVaultClientId) {
$runAlPipelineParams += @{
"KeyVaultCertPfxFile" = $keyVaultCertificateUrl
"keyVaultCertPfxPassword" = ConvertTo-SecureString -string $keyVaultCertificatePassword
"keyVaultClientId" = $keyVaultClientId
}
}
$previousApps = @()
if (!$settings.skipUpgrade) {
Write-Host "::group::Locating previous release"
try {
$latestRelease = GetLatestRelease -token $token -api_url $ENV:GITHUB_API_URL -repository $ENV:GITHUB_REPOSITORY -ref $ENV:GITHUB_REF_NAME
if ($latestRelease) {
Write-Host "Using $($latestRelease.name) (tag $($latestRelease.tag_name)) as previous release"
$artifactsFolder = Join-Path $baseFolder "artifacts"
New-Item $artifactsFolder -ItemType Directory | Out-Null
DownloadRelease -token $token -projects $project -api_url $ENV:GITHUB_API_URL -repository $ENV:GITHUB_REPOSITORY -release $latestRelease -path $artifactsFolder -mask "Apps"
$previousApps += @(Get-ChildItem -Path $artifactsFolder | ForEach-Object { $_.FullName })
}
else {
OutputWarning -message "No previous release found"
}
}
catch {
OutputError -message "Error trying to locate previous release. Error was $($_.Exception.Message)"
exit
}
Write-Host "::endgroup::"
}
$additionalCountries = $settings.additionalCountries
$imageName = ""
if (-not $gitHubHostedRunner) {
$imageName = $settings.cacheImageName
if ($imageName) {
Write-Host "::group::Flush ContainerHelper Cache"
Flush-ContainerHelperCache -cache 'all,exitedcontainers' -keepdays $settings.cacheKeepDays
Write-Host "::endgroup::"
}
}
$authContext = $null
$environmentName = ""
$CreateRuntimePackages = $false
if ($settings.versioningStrategy -eq -1) {
$artifactVersion = [Version]$settings.artifact.Split('/')[4]
$runAlPipelineParams += @{
"appVersion" = "$($artifactVersion.Major).$($artifactVersion.Minor)"
}
$appBuild = $artifactVersion.Build
$appRevision = $artifactVersion.Revision
}
elseif (($settings.versioningStrategy -band 16) -eq 16) {
$runAlPipelineParams += @{
"appVersion" = $settings.repoVersion
}
}
$allTestResults = "testresults*.xml"
$testResultsFile = Join-Path $projectPath "TestResults.xml"
$testResultsFiles = Join-Path $projectPath $allTestResults
if (Test-Path $testResultsFiles) {
Remove-Item $testResultsFiles -Force
}
$buildOutputFile = Join-Path $projectPath "BuildOutput.txt"
$containerEventLogFile = Join-Path $projectPath "ContainerEventLog.evtx"
Add-Content -Encoding UTF8 -Path $env:GITHUB_ENV -Value "containerName=$containerName"
Set-Location $projectPath
$runAlPipelineOverrides | ForEach-Object {
$scriptName = $_
$scriptPath = Join-Path $ALGoFolderName "$ScriptName.ps1"
if (Test-Path -Path $scriptPath -Type Leaf) {
Write-Host "Add override for $scriptName"
Trace-Information -Message "Using override for $scriptName"
$runAlPipelineParams += @{
"$scriptName" = (Get-Command $scriptPath | Select-Object -ExpandProperty ScriptBlock)
}
}
}
if ($runAlPipelineParams.Keys -notcontains 'RemoveBcContainer') {
$runAlPipelineParams += @{
"RemoveBcContainer" = {
Param([Hashtable]$parameters)
Remove-BcContainerSession -containerName $parameters.ContainerName -killPsSessionProcess
Remove-BcContainer @parameters
}
}
}
if ($runAlPipelineParams.Keys -notcontains 'ImportTestDataInBcContainer') {
if (($settings.configPackages) -or ($settings.Keys | Where-Object { $_ -like 'configPackages.*' })) {
Write-Host "Adding Import Test Data override"
Write-Host "Configured config packages:"
$settings.Keys | Where-Object { $_ -like 'configPackages*' } | ForEach-Object {
Write-Host "- $($_):"
$settings."$_" | ForEach-Object {
Write-Host " - $_"
}
}
$runAlPipelineParams += @{
"ImportTestDataInBcContainer" = {
Param([Hashtable]$parameters)
$country = Get-BcContainerCountry -containerOrImageName $parameters.containerName
$prop = "configPackages.$country"
if ($settings.Keys -notcontains $prop) {
$prop = "configPackages"
}
if ($settings."$prop") {
Write-Host "Importing config packages from $prop"
$settings."$prop" | ForEach-Object {
$configPackage = $_.Split(',')[0].Replace('{COUNTRY}',$country)
$packageId = $_.Split(',')[1]
UploadImportAndApply-ConfigPackageInBcContainer `
-containerName $parameters.containerName `
-companyName $settings.companyName `
-Credential $parameters.credential `
-Tenant $parameters.tenant `
-ConfigPackage $configPackage `
-PackageId $packageId
}
}
}
}
}
}
if ((($bcContainerHelperConfig.ContainsKey('TrustedNuGetFeeds') -and ($bcContainerHelperConfig.TrustedNuGetFeeds.Count -gt 0)) -or ($gitHubPackagesContext)) -and ($runAlPipelineParams.Keys -notcontains 'InstallMissingDependencies')) {
if ($githubPackagesContext) {
$gitHubPackagesCredential = $gitHubPackagesContext | ConvertFrom-Json
}
else {
$gitHubPackagesCredential = [PSCustomObject]@{ "serverUrl" = ''; "token" = '' }
}
$runAlPipelineParams += @{
"InstallMissingDependencies" = {
Param([Hashtable]$parameters)
$parameters.missingDependencies | ForEach-Object {
$appid = $_.Split(':')[0]
$appName = $_.Split(':')[1]
$version = $appName.SubString($appName.LastIndexOf('_')+1)
$version = [System.Version]$version.SubString(0,$version.Length-4)
$publishParams = @{
"nuGetServerUrl" = $gitHubPackagesCredential.serverUrl
"nuGetToken" = GetAccessToken -token $gitHubPackagesCredential.token -permissions @{"packages"="read";"contents"="read";"metadata"="read"} -repositories @()
"packageName" = $appId
"version" = $version
"select" = $settings.nuGetFeedSelectMode
}
if ($parameters.ContainsKey('CopyInstalledAppsToFolder')) {
$publishParams += @{
"CopyInstalledAppsToFolder" = $parameters.CopyInstalledAppsToFolder
}
}
if ($parameters.ContainsKey('containerName')) {
Publish-BcNuGetPackageToContainer -containerName $parameters.containerName -tenant $parameters.tenant -skipVerification -appSymbolsFolder $parameters.appSymbolsFolder @publishParams -ErrorAction SilentlyContinue
}
else {
if ($parameters.ContainsKey('installedApps') -and $parameters.ContainsKey('installedCountry')) {
foreach($installedApp in $parameters.installedApps) {
if ($installedApp.Id -eq $platformAppId) {
$publishParams += @{
"installedApps" = $parameters.installedApps
"installedPlatform" = ([System.Version]$installedApp.Version)
"installedCountry" = $parameters.installedCountry
}
break
}
}
}
Download-BcNuGetPackageToFolder -folder $parameters.appSymbolsFolder @publishParams | Out-Null
}
}
}
}
}
"enableTaskScheduler",
"assignPremiumPlan",
"doNotBuildTests",
"doNotRunTests",
"doNotRunBcptTests",
"doNotRunPageScriptingTests",
"doNotPublishApps",
"installTestRunner",
"installTestFramework",
"installTestLibraries",
"installPerformanceToolkit",
"enableCodeCop",
"enableAppSourceCop",
"enablePerTenantExtensionCop",
"enableUICop",
"enableCodeAnalyzersOnTestApps",
"useCompilerFolder" | ForEach-Object {
if ($settings."$_") { $runAlPipelineParams += @{ "$_" = $true } }
}
if ($buildMode -eq 'Translated') {
if ($runAlPipelineParams.Keys -notcontains 'features') {
$runAlPipelineParams["features"] = @()
}
Write-Host "Adding translationfile feature"
$runAlPipelineParams["features"] += "translationfile"
}
if ($runAlPipelineParams.Keys -notcontains 'preprocessorsymbols') {
$runAlPipelineParams["preprocessorsymbols"] = @()
}
# DEPRECATION: REMOVE AFTER April 1st 2025 --->
if ($buildMode -eq 'Clean' -and $settings.ContainsKey('cleanModePreprocessorSymbols')) {
Write-Host "Adding Preprocessor symbols : $($settings.cleanModePreprocessorSymbols -join ',')"
$runAlPipelineParams["preprocessorsymbols"] += $settings.cleanModePreprocessorSymbols
Trace-DeprecationWarning -Message "cleanModePreprocessorSymbols is deprecated" -DeprecationTag "cleanModePreprocessorSymbols"
}
# <--- REMOVE AFTER April 1st 2025
if ($settings.ContainsKey('preprocessorSymbols')) {
Write-Host "Adding Preprocessor symbols : $($settings.preprocessorSymbols -join ',')"
$runAlPipelineParams["preprocessorsymbols"] += $settings.preprocessorSymbols
}
Write-Host "Invoke Run-AlPipeline with buildmode $buildMode"
Run-AlPipeline @runAlPipelineParams `
-accept_insiderEula `
-pipelinename $workflowName `
-containerName $containerName `
-imageName $imageName `
-bcAuthContext $authContext `
-environment $environmentName `
-artifact $settings.artifact.replace('{INSIDERSASTOKEN}','') `
-vsixFile $settings.vsixFile `
-companyName $settings.companyName `
-memoryLimit $settings.memoryLimit `
-baseFolder $projectPath `
-sharedFolder $sharedFolder `
-licenseFile $licenseFileUrl `
-installApps $install.apps `
-installTestApps $install.testApps `
-installOnlyReferencedApps:$settings.installOnlyReferencedApps `
-generateDependencyArtifact `
-updateDependencies:$settings.updateDependencies `
-previousApps $previousApps `
-appFolders $settings.appFolders `
-testFolders $settings.testFolders `
-bcptTestFolders $settings.bcptTestFolders `
-pageScriptingTests $settings.pageScriptingTests `
-restoreDatabases $settings.restoreDatabases `
-buildOutputFile $buildOutputFile `
-containerEventLogFile $containerEventLogFile `
-testResultsFile $testResultsFile `
-testResultsFormat 'JUnit' `
-customCodeCops $settings.customCodeCops `
-gitHubActions `
-failOn $settings.failOn `
-treatTestFailuresAsWarnings:$settings.treatTestFailuresAsWarnings `
-rulesetFile $settings.rulesetFile `
-enableExternalRulesets:$settings.enableExternalRulesets `
-appSourceCopMandatoryAffixes $settings.appSourceCopMandatoryAffixes `
-additionalCountries $additionalCountries `
-obsoleteTagMinAllowedMajorMinor $settings.obsoleteTagMinAllowedMajorMinor `
-buildArtifactFolder $buildArtifactFolder `
-pageScriptingTestResultsFile (Join-Path $buildArtifactFolder 'PageScriptingTestResults.xml') `
-pageScriptingTestResultsFolder (Join-Path $buildArtifactFolder 'PageScriptingTestResultDetails') `
-CreateRuntimePackages:$CreateRuntimePackages `
-appBuild $appBuild -appRevision $appRevision `
-uninstallRemovedApps
# If any apps were downloaded as part of incremental builds in a pr, we should remove them again after the build to prevent them from being included in artifacts
if ($ENV:GITHUB_EVENT_NAME -like 'pull_request*' -and $downloadedAppsByType) {
$downloadedAppsByType | ForEach-Object {
if ($_.downloadedApps) {
$mask = $_.mask
$thisArtifactFolder = Join-Path $buildArtifactFolder $mask
Write-Host "Removing pre-built apps from $thisArtifactFolder"
foreach($downloadedApp in $_.downloadedApps) {
$thisApp = Join-Path $thisArtifactFolder $downloadedApp
try {
if (Test-Path $thisApp) {
Remove-Item $thisApp
}
Write-Host "Removed pre-built app: $thisApp"
} catch {
Write-Host "Failed to remove pre-built app: $thisApp"
}
}
}
}
}
if ($containerBaseFolder) {
Write-Host "Copy artifacts and build output back from build container"
$destFolder = Join-Path $ENV:GITHUB_WORKSPACE $project
Copy-Item -Path (Join-Path $projectPath ".buildartifacts") -Destination $destFolder -Recurse -Force
Copy-Item -Path (Join-Path $projectPath ".output") -Destination $destFolder -Recurse -Force
Copy-Item -Path (Join-Path $projectPath "testResults*.xml") -Destination $destFolder
Copy-Item -Path (Join-Path $projectPath "bcptTestResults*.json") -Destination $destFolder
Copy-Item -Path $buildOutputFile -Destination $destFolder -Force -ErrorAction SilentlyContinue
Copy-Item -Path $containerEventLogFile -Destination $destFolder -Force -ErrorAction SilentlyContinue
}
}
catch {
throw
}
finally {
try {
if (Test-BcContainer -containerName $containerName) {
Write-Host "Get Event Log from container"
$eventlogFile = Get-BcContainerEventLog -containerName $containerName -doNotOpen
Copy-Item -Path $eventLogFile -Destination $containerEventLogFile
if ($project) {
# Copy event log to project folder if multiproject
$destFolder = Join-Path $ENV:GITHUB_WORKSPACE $project
Copy-Item -Path $containerEventLogFile -Destination $destFolder
}
}
}
catch {
Write-Host "Error getting event log from container: $($_.Exception.Message)"
}
if ($containerBaseFolder -and (Test-Path $containerBaseFolder) -and $projectPath -and (Test-Path $projectPath)) {
Write-Host "Removing temp folder"
Remove-Item -Path (Join-Path $projectPath '*') -Recurse -Force
Write-Host "Done"
}
}