Skip to content
Draft
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
127 changes: 127 additions & 0 deletions azure-pipelines-PR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -890,3 +890,130 @@ stages:
- pwsh: .\tests\ILVerify\ilverify.ps1
displayName: Run ILVerify
workingDirectory: $(Build.SourcesDirectory)

# ============================================================================
# FAILURE REPORTING STAGE
# ============================================================================
- stage: report_failures
displayName: Report Build and Test Failures
dependsOn: build
condition: and(
always(),
eq(variables['Build.Reason'], 'PullRequest'),
eq(variables['System.TeamProject'], 'public'),
or(
eq(dependencies.build.result, 'Failed'),
eq(dependencies.build.result, 'SucceededWithIssues')
))
jobs:
- job: CollectAndReportFailures
displayName: 'Report Build and Test Failures to GitHub PR'
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: self

# Check if PR author and assignee are allowed to receive failure reports
- task: PowerShell@2
displayName: 'Check PR Author and Assignee'
name: 'CheckAssignee'
inputs:
targetType: 'inline'
script: |
$allowedUsers = @('abonie', 'copilot', 'T-Gro')
$shouldRunReport = $false

try {
$prNumber = "$(System.PullRequest.PullRequestNumber)"
$repoName = "$(Build.Repository.Name)"

if ([string]::IsNullOrEmpty($prNumber) -or [string]::IsNullOrEmpty($repoName)) {
Write-Host "Missing PR number or repository name, skipping author/assignee check"
Write-Host "##vso[task.setvariable variable=shouldRunReport;isOutput=true]false"
exit 0
}

# Get PR details from GitHub API
$headers = @{
'Authorization' = "token $env:GITHUB_TOKEN"
'Accept' = 'application/vnd.github.v3+json'
'User-Agent' = 'Azure-DevOps-Build-Reporter'
}

$prUrl = "https://api.github.com/repos/$repoName/pulls/$prNumber"
Write-Host "Checking PR author and assignees for: $prUrl"

$prData = Invoke-RestMethod -Uri $prUrl -Headers $headers -Method Get

# Check PR author
$authorLogin = $prData.user.login
Write-Host "PR author: $authorLogin"

$isAuthorAllowed = $authorLogin -in $allowedUsers
Write-Host "Is author allowed: $isAuthorAllowed"

# Check PR assignees
$assigneeLogins = @()
if ($prData.assignees -and $prData.assignees.Count -gt 0) {
$assigneeLogins = $prData.assignees | ForEach-Object { $_.login }
Write-Host "PR assignee(s): $($assigneeLogins -join ', ')"
} else {
Write-Host "PR has no assignees"
}

# Check if any assignee is in the allowed list
$allowedAssignee = $assigneeLogins | Where-Object { $_ -in $allowedUsers } | Select-Object -First 1
$hasAllowedAssignee = $null -ne $allowedAssignee

Write-Host "Has allowed assignee: $hasAllowedAssignee"
if ($hasAllowedAssignee) {
Write-Host "Found allowed assignee: '$allowedAssignee'"
}

# Both conditions must be met: author must be allowed AND at least one assignee must be allowed
if ($isAuthorAllowed -and $hasAllowedAssignee) {
Write-Host "Failure report will be generated (author '$authorLogin' is allowed and found allowed assignee: '$allowedAssignee')"
$shouldRunReport = $true
} else {
if (-not $isAuthorAllowed) {
Write-Host "Author '$authorLogin' is not in the allowed users list: $($allowedUsers -join ', ')"
}
if (-not $hasAllowedAssignee) {
if ($assigneeLogins.Count -gt 0) {
Write-Host "No allowed assignees found. Assignees: $($assigneeLogins -join ', ')"
} else {
Write-Host "PR has no assignees"
}
}
Write-Host "Skipping failure report - both author and assignee must be from allowed users list"
}
}
catch {
Write-Warning "Failed to check PR author/assignee: $($_.Exception.Message)"
Write-Host "Setting shouldRunReport to false due to error"
}

Write-Host "##vso[task.setvariable variable=shouldRunReport;isOutput=true]$shouldRunReport"
Write-Host "Final decision: shouldRunReport = $shouldRunReport"
pwsh: true
env:
GITHUB_TOKEN: $(github-pat)
continueOnError: true

# Run the failure reporting script
- task: PowerShell@2
displayName: 'Generate and Post Failure Report'
inputs:
filePath: '$(Build.SourcesDirectory)/eng/scripts/Report-BuildFailures.ps1'
arguments: >-
-BuildId $(Build.BuildId)
-Organization "$(System.CollectionUri)"
-Project "$(System.TeamProject)"
-Repository "$(Build.Repository.Name)"
-PullRequestId $(System.PullRequest.PullRequestNumber)
pwsh: true
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
GITHUB_TOKEN: $(github-pat)
condition: and(always(), eq(variables['CheckAssignee.shouldRunReport'], 'true'))
continueOnError: true
Loading
Loading