【问题标题】:Azure DevOps pipeline fails when running pylint运行 pylint 时 Azure DevOps 管道失败
【发布时间】:2026-02-08 01:25:02
【问题描述】:

作为 Azure DevOps 管道的第一步,我希望通过运行 pylint 来验证我的 Python 文件。这会导致管道失败。 我的项目在这个地址是公开的:

https://dev.azure.com/gcr84/dark-matter-attractor

所有代码都在 repo 中可见,并且管道运行历史记录可用。我想了解为什么 pylinting 导致管道失败,我尝试添加命令:

"|| pylint-exit $?"

(见https://pypi.org/project/pylint-exit/),

还有

failOnStderr: false

(见https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/bash?view=azure-devops)。

下面是我的 bash 命令:

- bash: find -name '*.py' | xargs pylint || pylint-exit $?
  displayName: 'Run pylint'
  failOnStderr: false

【问题讨论】:

  • 您是否在运行管道时启用了系统诊断?您可以更详细地检查错误。
  • @MoonHorse 我试过了,手动运行管道。结果是: ##[debug]Exit code 1 received from tool '/bin/bash' ##[debug]STDIO 流已关闭工具 '/bin/bash' ##[error]Bash 以代码 '1' 退出.我不太确定如何从中取得进展

标签: bash azure-devops pylint


【解决方案1】:

检查您的日志后,这似乎是与 Azure DevOps 方面无关的预期行为。

  - fatal message issued

  - error message issued

  - refactor message issued

  - convention message issued

  - usage error

Fatal messages detected.  Failing...

这引发了错误退出代码 1,最终使 bash 任务失败。

如果配置了failOnStderr=false,则只有在将任何错误写入stderr 时才会阻止此任务失败。并非所有错误都被忽略。

如果不想处理python-pylint 'C0103:Invalid constant name等错误。解决方法应该是添加continueOnError: true

- bash: find -name '*.py' | xargs pylint || pylint-exit $?
  displayName: 'Run pylint'
  failOnStderr: false
  continueOnError: true

这将强制您的构建继续运行。此外,您还可以尝试使用一些 3rd 方扩展来运行 pylink,例如--PyLint Checker

【讨论】:

  • 感谢您的帮助,现在我的管道运行顺利。我使用了您设置 continueOnError: true 的提示,并且还将尝试 PyLint Checker。
最近更新 更多