1

We are setting up Azure DevOps pipelines that are used for required checks in pull requests. In various of these pipelines, we execute custom code with script blocks:

- script: |
    ...
  displayName: "Execute XYZ"
  continueOnError: false

If this script fails, the pipeline as a whole fails, which is fine.

However, the pull request overview page in DevOps then displays this information:

errors in PR overview page

That is:

  • A red X icon and the message "1 of ... required checks failed", quite visible, but very superficial.
  • A red X icon and the name of the failed check. Equally visible as the previous one, but not very detailed in the case of complex multi-step checks, either.
  • The message "Integrate / ". This is actually somewhat helpful, but it is styled in such a way that I barely perceive it when skimming over the page.
  • The actual error message, styled with extreme contrast to the rest of the page, and literally the first thing that catches my attention when I look at the page.

This last element is where I expect a maximum of concrete information about the issue. Unfortunately, the message displayed here when a script fails is totally useless:

Bash exited with code '1'.

It is safe to say that if the PR shows this, many developers in the team might assume there is something wrong with the pipeline and contact (and thereby block) the DevOps admins, rather than check the build details themselves.

What I'd expect to be shown there would be e.g. (depending on what the script actually does):

  • "2 error(s) occurred in the unit tests."
  • "Styleguide violations detected in files Info.ts, List.ts, and 5 more."
  • "Required file /PluginManifest.xml is missing."

Clearly, I can provide such a message in the script block, where appropriate, but the question is: Can I somehow make this message appear in the error summary on the PR overview page instead of that nondescript return code?

F-H
  • 663
  • 1
  • 10
  • 21

2 Answers2

0

You will not be able to change this behavior but you can add comments to PR.

Please take a look here at this reply on SO. It will allow you to add any markdown-style text to PR. Even something like this enter image description here

If you want to add something simpler you can use this code

  - powershell: |
      $body = @"
      {
          "comments": [
            {
              "parentCommentId": 0,
              "content": "Your comment here",
              "commentType": 1
            }
          ],
          "status": 4
        }
      "@
      $url = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$env:SYSTEM_TEAMPROJECTID/_apis/git/repositories/$($env:Build_Repository_Name)/pullRequests/$($env:System_PullRequest_PullRequestId)/threads?api-version=5.1"
      $result = Invoke-RestMethod -Uri $url -Method POST -Headers @{Authorization = "Bearer $(System.AccessToken)"} -Body $Body -ContentType application/json
    displayName: Post comment on PR

But before that, ensure your build service has permission to contribute to pull requests in your repository.

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
0

Actually, the answer was already in another question:

Logging Commands are the solution here. Writing "##vso[task.logissue type=error;]..." to stdout will make whatever you write instead of ... appear in the error summary, if it's the first error logged.

Note that this just places the error message in the output; you still have to make sure separately that your script (and thereby the pipeline stage) is actually considered failed, for example by explicitly setting a non-zero exit code.

F-H
  • 663
  • 1
  • 10
  • 21