Discord Azure Notification

This commit is contained in:
Qstick 2020-04-22 17:04:43 -04:00
parent d30c1b1385
commit df76c679ff
1 changed files with 100 additions and 0 deletions

View File

@ -788,3 +788,103 @@ stages:
codeCoverageTool: 'cobertura'
summaryFileLocation: './CoverageResults/combined/Cobertura.xml'
reportDirectory: './CoverageResults/combined/'
- stage: Report_Out
dependsOn:
- Analyze
- Unit_Test
- Integration
- Automation
condition: always()
displayName: Build Status Report
jobs:
- job:
displayName: Discord Notification
pool:
vmImage: 'ubuntu-18.04'
steps:
- checkout: none
- bash: |
env | sort
if [[ $BUILD_REASON == "PullRequest" ]]; then
echo "##vso[task.setvariable variable=buildTypeString][PR $SYSTEM_PULLREQUEST_PULLREQUESTNUMBER]($SYSTEM_PULLREQUEST_SOURCEREPOSITORYURI/pull/$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER) to \`$SYSTEM_PULLREQUEST_TARGETBRANCH\` from \`$SYSTEM_PULLREQUEST_SOURCEBRANCH\`"
COMMIT_SHORT=$(echo $SYSTEM_PULLREQUEST_SOURCECOMMITID | cut -c1-7)
echo "##vso[task.setvariable variable=commitUrl]$SYSTEM_PULLREQUEST_SOURCEREPOSITORYURI/commit/$SYSTEM_PULLREQUEST_SOURCECOMMITID"
else
echo "##vso[task.setvariable variable=buildTypeString]Mainline Branch '$BUILD_SOURCEBRANCHNAME'"
COMMIT_SHORT=$(echo $BUILD_SOURCEVERSION | cut -c1-7)
echo "##vso[task.setvariable variable=commitUrl]$SYSTEM_PULLREQUEST_SOURCEREPOSITORYURI/commit/$BUILD_SOURCEVERSION"
fi
echo "##vso[task.setvariable variable=commitString]$COMMIT_SHORT"
- powershell: |
$bearer_token = "$env:SYSTEM_ACCESSTOKEN"
$headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($bearer_token)")) }
$url = "https://dev.azure.com/Radarr/Radarr/_apis/test/runs?buildUri=$env:BUILD_BUILDURI&api-version=5.1"
$response = (Invoke-RestMethod -Uri $url -Headers $headers).value
$passed_tests = $response | Select passedTests | Measure-Object -Sum PassedTests | Select-Object -expand Sum
$failed_tests = $response | Select unanalyzedTests | Measure-Object -Sum UnanalyzedTests | Select-Object -expand Sum
$skipped_tests = $response | Select notApplicableTests | Measure-Object -Sum NotApplicableTests | Select-Object -expand Sum
$url1 = "https://dev.azure.com/Radarr/Radarr/_apis/test/codeCoverage?buildId=$env:BUILD_BUILDID&api-version=5.1-preview"
$response1 = (Invoke-RestMethod -Uri $url1 -Headers $headers).coverageData.coverageStats
$total_lines = $response1 | Where-Object {$_.Label -eq "Lines"} | Select-Object -expand Total
$covered_lines = $response1 | Where-Object {$_.Label -eq "Lines"} | Select-Object -expand Covered
$coverage_percent = [math]::Round($covered_lines/$total_lines*100,2)
$url2 = "https://dev.azure.com/Radarr/Radarr/_apis/build/builds/$env:BUILD_BUILDID/timeline/?api-version=5.1"
$response2 = (Invoke-RestMethod -Uri $url2 -Headers $headers).records
$failed_tasks = $response2 | Where-Object {$_.Result -eq "failed"} | Measure-Object | Select-Object -expand Count
$error_count = $response2 | Select errorCount | Measure-Object -Sum ErrorCount | Select-Object -expand Sum
$warning_count = $response2 | Select warningCount | Measure-Object -Sum WarningCount | Select-Object -expand Sum
if($failed_tasks -gt 0) {
$status_message = "Failed"
Write-Host "##vso[task.setvariable variable=statusColor;]15158332"
}else {
$status_message = "Success"
Write-Host "##vso[task.setvariable variable=statusColor;]3066993"
}
Write-Host "##vso[task.setvariable variable=testResultString;]$passed_tests Passed, $failed_tests Failed, $skipped_tests Skipped"
Write-Host "##vso[task.setvariable variable=coverageString;]$coverage_percent% ($covered_lines of $total_lines lines)"
Write-Host "##vso[task.setvariable variable=statusString;]$status_message ($error_count Errors, $warning_count Warning)"
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
- task: ado-discord-webhook@1
displayName: Send Webhook Payload
inputs:
channelId: $(discordChannelId)
webhookKey: $(discordWebhookKey)
name: 'AzureBot'
messageType: 'embeds'
embeds: |
[{
"title": "Build $(Build.BuildNumber) [$(Build.Repository.Name)]",
"url": "$(System.CollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId)",
"color": $(statusColor),
"fields": [
{
"name": "Author",
"value": "[$(Build.SourceVersionAuthor)](https://github.com/$(Build.SourceVersionAuthor))",
"inline": true
},
{
"name": "Commit",
"value": "[`$(commitString)`]($(commitUrl))",
"inline": true
},
{
"name": "Build Type",
"value": "$(buildTypeString)"
},
{
"name": "Test Results",
"value": "`$(testResultString)`"
},
{
"name": "Coverage",
"value": "`$(coverageString)`"
},
{
"name": "Status",
"value": "$(statusString)",
"inline": true
}
]
}]