azure-devopsazure-pipelineserror-messaging

How to make script output a more meaningful error message?


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:

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):

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?


Solution

  • 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.