简体   繁体   English

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

[英]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.

相关问题 Azure Devops Pipeline 中的 Python 脚本执行 - Python script execution in Azure Devops Pipeline Azure Devops Pipeline 中的 Python 脚本不能使用库中的值,如果它是一个秘密 - Python script in Azure Devops Pipeline cannot use a value from library if it's a secret 使用 python 从 azure function 触发 Azure Devops 管道 - Trigger an Azure Devops pipeline from an azure function using python 在 Azure Devops 管道中安装 Python 要求时出错 - Error when installing Python requirements in Azure Devops pipeline 如何在 azure devops 管道上进行 python 覆盖测试时引发错误? - How can i raising error while python coverage test on azure devops pipeline? DevOps 管道在导入 azureml.core 时运行 python 脚本错误 - DevOps pipeline running python script error on import azureml.core 如何从 azure 管道获取存储在 python 脚本中的变量的值 - how to get the value of a variable stored in a python script from azure pipeline 如何阻止构建代理在 Azure devops 的管道进程中等待 - How to stop build agent from waiting in the pipeline process in Azure devops 在 Azure Devops 发布管道中启动 Python 看门狗 - Launching a Python watchdog in an Azure Devops Release pipeline 找不到Azure Devops发布管道Python模块 - Azure Devops Release Pipeline Python Module Not Found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM