4

I'm using python in my build pipeline to run some checks on pull requests. When checks fail, I use sys.exit('reason') to exit the script. This works but the output is not helpful. All that's shown in the PR page is this:

The process 'C:\hostedtoolcache\windows\Python\3.7.9\x64\python.exe' failed with exit code 1

I would like to know how to pass the reason to this page so the developers don't have to dig into the pipeline log to see what actually went wrong. In powershell I can use the following commands:

Write-Host "##vso[task.logissue type=error;]Reason"
Write-Host "##vso[task.complete result=Failed;]Text"
Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
teegee
  • 63
  • 9

1 Answers1

6

You can use the same logging commands in python also, with print():

steps:
- task: PythonScript@0
  inputs:
    scriptSource: inline
    script: |
     print("##vso[task.logissue type=error;]Reason")
     print("##vso[task.complete result=Failed;]Text")

In the PR you will see:

enter image description here

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114