gpt4 book ai didi

python - 如何从 python 脚本在 azure devops 管道中生成合理的错误消息

转载 作者:行者123 更新时间:2023-12-05 02:43:51 26 4
gpt4 key购买 nike

我在我的构建管道中使用 python 对拉取请求运行一些检查。当检查失败时,我使用 sys.exit('reason') 退出脚本。这有效,但输出没有帮助。 PR 页面中显示的是:

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

我想知道如何将原因传递给此页面,这样开发人员就不必深入研究管道日志来查看实际出了什么问题。在 powershell 中,我可以使用以下命令:

Write-Host "##vso[task.logissue type=error;]Reason"
Write-Host "##vso[task.complete result=Failed;]Text"

最佳答案

您可以使用相同的 logging commands在 python 中也可以使用 print():

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

在 PR 中你会看到:

enter image description here

关于python - 如何从 python 脚本在 azure devops 管道中生成合理的错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66738557/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com