Skip to content

Commit

Permalink
[devops] Improve comment when a build completes. (#21685)
Browse files Browse the repository at this point in the history
Always report the build status, that way we'll automatically hide any previous
build failure comments.
  • Loading branch information
rolfbjarne authored Dec 2, 2024
1 parent c9c54a2 commit 693c8bc
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions tools/devops/automation/templates/build/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,23 @@ steps:
keyringPass: ${{ parameters.keyringPass }}
use1ES: ${{ parameters.use1ES }}

# if we failed, write a comment and set the pipeline to failure. In this case, we do not want to hide the fact that we failed but we also want
# to write a comment.
# report the result of the build.
- pwsh: |
Import-Module $Env:SYSTEM_DEFAULTWORKINGDIRECTORY\$Env:BUILD_REPOSITORY_TITLE\tools\devops\automation\scripts\MaciosCI.psd1
$githubComments = New-GitHubCommentsObjectFromUrl -Url "$(Build.Repository.Uri)" -Token $(GitHub.Token) -Hash $Env:COMMENT_HASH
$githubComments.NewCommentFromMessage("Build failed", ":fire:", "Build failed for the job '$(System.JobDisplayName)'", "build")
condition: failed()
displayName: 'Report build failure'
$commentMessage = [System.Text.StringBuilder]::new()
if (("$Env:AGENT_JOBSTATUS" -eq "Succeeded") -or ("$Env:AGENT_JOBSTATUS" -eq "SucceededWithIssues")) {
$commentTitle = "Build passed ($(System.JobDisplayName))"
$commentIcon = ":white_check_mark:"
$commentMessage.AppendLine("")
} else {
$commentTitle = "Build failed ($(System.JobDisplayName))"
$commentIcon = ":fire:"
$commentMessage.AppendLine("Build failed for the job '$(System.JobDisplayName)' (with job status '$Env:AGENT_JOBSTATUS')")
}
$githubComments.NewCommentFromMessage($commentTitle, $commentIcon, $commentMessage.ToString(), "build $(System.JobDisplayName)")
condition: always()
displayName: 'Report build result'
env:
${{ if eq(parameters.repositoryAlias, 'self') }}:
COMMENT_HASH: $(fix_commit.GIT_HASH)
Expand Down

9 comments on commit 693c8bc

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.