diff --git a/pipelines/snippets.yml b/pipelines/snippets.yml index 67d0d07db..4da6f6ee9 100644 --- a/pipelines/snippets.yml +++ b/pipelines/snippets.yml @@ -22,7 +22,7 @@ resources: ref: main pool: - vmImage: 'ubuntu-latest' + name: 1es-ubuntu-latest parameters: @@ -178,6 +178,7 @@ stages: inputs: artifact: 'Generation Test Results' path: '$(Build.ArtifactStagingDirectory)/TestResults' + - pwsh: | Write-Host "Installing module ImportExcel" Install-Module -Name ImportExcel -Scope CurrentUser -Force -AllowClobber @@ -188,19 +189,29 @@ stages: workingDirectory: '$(Build.SourcesDirectory)' - pwsh: | - Write-Host "create file appSettings.json in the workingDirectory" - New-Item -Path $(Build.SourcesDirectory) -Name "appSettings.json" -ItemType "file" -Force Write-Host "Creating folder Reports" New-Item -Path $(Build.SourcesDirectory) -Name "Reports" -ItemType "Directory" -Force displayName: Create requisite directory items - - pwsh: | - $ErrorActionPreference="Continue" - $(Build.SourcesDirectory)/scripts/categorizeErrors.ps1 -trxFolderPath '$(Build.ArtifactStagingDirectory)/TestResults/' -txtOutputFolderPath '$(Build.ArtifactStagingDirectory)/Reports/' + - task: AzurePowerShell@5 + inputs: + azureSubscription: "RaptorServiceFederationConnection" + ScriptType: "FilePath" + ScriptPath: "$(Build.SourcesDirectory)/scripts/categorizeErrors.ps1" + ScriptArguments: " + -trxFolderPath '$(Build.ArtifactStagingDirectory)/TestResults/' + -reportOutputPath '$(Build.ArtifactStagingDirectory)/Reports/' + -snippetsBaseErrorPath '$(Build.ArtifactStagingDirectory)' + " + workingDirectory: '$(Build.SourcesDirectory)' + pwsh: true + azurePowerShellVersion: latestVersion + failOnStandardError: true displayName: Generate error category report - workingDirectory: '$(Build.SourcesDirectory)' env: - RAPTOR_CONFIGCONNECTIONSTRING: $(RAPTOR_CONFIGCONNECTIONSTRING) + RAPTOR_CONFIGENDPOINT: $(RAPTOR_CONFIGENDPOINT) + RAPTOR_CONFIGMANAGEDIDENTITY_ID: $(RAPTOR_CONFIGMANAGEDIDENTITY_ID) + WorkingDirectory: '$(Build.SourcesDirectory)' continueOnError: true - task: PublishBuildArtifacts@1 diff --git a/scripts/categorizeErrors.ps1 b/scripts/categorizeErrors.ps1 index 0d2846ce1..bb8e38146 100644 --- a/scripts/categorizeErrors.ps1 +++ b/scripts/categorizeErrors.ps1 @@ -1,8 +1,10 @@ param( [Parameter(Mandatory=$true)] [string]$trxFolderPath, + [Parameter(Mandatory=$true)] + [string]$snippetsBaseErrorPath, [Parameter(Mandatory=$false)] - [string]$txtOutputFolderPath + [string]$reportOutputPath ) Import-Module ImportExcel @@ -13,10 +15,10 @@ if (!(Test-Path $trxFolderPath)) exit } -#if $txtOutputFolderPath is not set, use current directory -if (-not $txtOutputFolderPath) +#if $reportOutputPath is not set, use current directory +if (-not $reportOutputPath) { - $txtOutputFolderPath = $PSScriptRoot + $reportOutputPath = $PSScriptRoot } $outcomeLocal = "Failed" # Only process failed tests @@ -36,7 +38,8 @@ $invalidStart = @() $other = @() $files = Get-ChildItem -Path $trxFolderPath -Exclude "http*" -$SpecificErrorPattern = "/home/vsts/work/1/a/Snippets/" + +$SpecificErrorPattern = "$snippetsBaseErrorPath/Snippets/" foreach ($trxFilePath in $files){ Write-Host "Processing file $trxFilePath" [xml]$xmlContent = Get-Content $trxFilePath @@ -109,7 +112,7 @@ foreach ($trxFilePath in $files){ } -$excelOutputPath = Join-Path $txtOutputFolderPath "report.xlsx" +$excelOutputPath = Join-Path $reportOutputPath "report.xlsx" $methodNotFound | Export-Excel -Path $excelOutputPath -WorksheetName "MethodNotFound" -AutoSize $pathNotFound | Export-Excel -Path $excelOutputPath -WorksheetName "PathNotFound" -AutoSize $invalidStart | Export-Excel -Path $excelOutputPath -WorksheetName "InvalidStart" -AutoSize diff --git a/scripts/getWorkloadOwner.ps1 b/scripts/getWorkloadOwner.ps1 index 27e66c1df..e9bb9e02e 100644 --- a/scripts/getWorkloadOwner.ps1 +++ b/scripts/getWorkloadOwner.ps1 @@ -27,16 +27,37 @@ function Get-AppSettings () return $AppSettings } # read app settings from Azure App Config - $appSettingsPath = "./appSettings.json" + $baseSettingsDirectory = $env:WorkingDirectory + if (!$baseSettingsDirectory) + { + $baseSettingsDirectory = $env:TEMP + } + New-Item -Path $baseSettingsDirectory -Name "appSettings.json" -Force + $appSettingsPath = Join-Path $baseSettingsDirectory "appSettings.json" -Resolve + write-host "appsettings path: $appSettingsPath" # Support Reading Settings from a Custom Label, otherwise default to Development $settingsLabel = $env:RAPTOR_CONFIGLABEL if ([string]::IsNullOrWhiteSpace($settingsLabel)) { $settingsLabel = "Development" } - az appconfig kv export --connection-string $env:RAPTOR_CONFIGCONNECTIONSTRING --label $settingsLabel --destination file --path $appSettingsPath --format json --yes - $appSettings = Get-Content $AppSettingsPath -Raw | ConvertFrom-Json - Remove-Item $appSettingsPath + try { + az login --identity -u $env:RAPTOR_CONFIGMANAGEDIDENTITY_ID #Pipeline login + # Disable below to test locally + # az login + Write-Host "Login successful. Fetching AppSettings from Azure App Config." + } + catch { + Write-Host "Failed to login using Managed Identity." + } + try { + az appconfig kv export --endpoint $env:RAPTOR_CONFIGENDPOINT --auth-mode login --label $settingsLabel --destination file --path $appSettingsPath --format json --yes + $appSettings = Get-Content $AppSettingsPath -Raw | ConvertFrom-Json + Remove-Item $appSettingsPath + } + catch { + Write-Host "Failed to fetch AppSettings from Azure App Config." + } if ( !$appSettings.CertificateThumbprint ` -or !$appSettings.ClientID `