Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update script to generate raptor report to login with managed ID #2096

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
fey101 marked this conversation as resolved.
Show resolved Hide resolved


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
Loading