Skip to content

Commit

Permalink
update script to generate raptor report to login with managed ID (#2096)
Browse files Browse the repository at this point in the history
* update script to generate raptor report to login with managed ID

* Add the username of managed identity

* Properly set managed identity login

* correctly specify working dir

* Change used pool to 1-es hosted pool

* separate installing of ImportExcel and creation of directory items

* ignore importExcel dependencies for autofit as aesthetics

* Add debug messages

* Debug some more. Working locally

* specify appSettings path explicitly

* fix base for fetching specificError

* make path to appSettings.json absoluteand present

* clean up
  • Loading branch information
fey101 authored Jul 10, 2024
1 parent 5b28369 commit 11a5cdc
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 18 deletions.
27 changes: 19 additions & 8 deletions pipelines/snippets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ resources:
ref: main

pool:
vmImage: 'ubuntu-latest'
name: 1es-ubuntu-latest


parameters:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
15 changes: 9 additions & 6 deletions scripts/categorizeErrors.ps1
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
29 changes: 25 additions & 4 deletions scripts/getWorkloadOwner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 `
Expand Down

0 comments on commit 11a5cdc

Please sign in to comment.