[英]How to generate sensible error messages in azure devops pipeline from a python script
I'm using python in my build pipeline to run some checks on pull requests.我在构建管道中使用 python 对拉取请求运行一些检查。 When checks fail, I use
sys.exit('reason')
to exit the script.当检查失败时,我使用
sys.exit('reason')
退出脚本。 This works but the output is not helpful.这可行,但 output 没有帮助。 All that's shown in the PR page is this:
PR页面中显示的所有内容都是这样的:
The process 'C:\hostedtoolcache\windows\Python\3.7.9\x64\python.exe' failed with exit code 1
进程“C:\hostedtoolcache\windows\Python\3.7.9\x64\python.exe”失败,退出代码为 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:
在 powershell 我可以使用以下命令:
Write-Host "##vso[task.logissue type=error;]Reason"
Write-Host "##vso[task.complete result=Failed;]Text"
You can use the same logging commands in python also, with print()
:您也可以在 python 中使用与
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:在 PR 你会看到:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.