Jenkins 与 pylint 导致构建失败
我添加了一个构建步骤来执行 Python 脚本。
在此脚本中,使用 lint.Run(..args) 调用 pylint 来检查代码。
该脚本有效,但最终构建失败,并显示唯一的错误消息:
构建步骤“执行 Python 脚本”将构建标记为失败
有人知道为什么会发生这种情况吗?
I added a build step to execute a Python script.
In this script pylint is called with the lint.Run(..args) to check the code.
The script works but in the end, the build fails with the only error message:
Build step 'Execute Python script' marked build as failure
Someone has an idea why this happens?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
今天遇到了这个(虽然没有使用詹金斯)。
就我而言,这是因为 Pylint 如何在其退出代码中编码 fatal-error-warning-refactor-convention-usage 信息:https://docs.pylint.org/en/1.6.0/run.html#exit-codes
我的修复:(
要点:https://gist.github.com/nkashy1/ae59d06d4bf81fb72047fcd390d08903)
Ran into this today (although not using Jenkins).
In my case it was because of how Pylint encodes fatal-error-warning-refactor-convention-usage info in its exit code: https://docs.pylint.org/en/1.6.0/run.html#exit-codes
My fix:
(Gist: https://gist.github.com/nkashy1/ae59d06d4bf81fb72047fcd390d08903)
Pylint 期望被分析的代码 100% 完美。
即使代码警告也可能导致以非零状态代码退出。
尝试按照 Pylint 建议修复您的代码并评分 10/10。
希望这有帮助。
Pylint expect the code being analyzed to be 100% perfect.
Even code warning may cause exit with non zero status code.
Try to fix your code as Pylint suggest and rate 10/10.
Hope this helps.
我同意@dmeister,但对于管道代码(Jenkinsfile),我建议尝试/捕获,然后解析错误。通过这种方式,您可以确定是否只是从 pylint 获取状态位(请参阅 Pylint 文档), pylint 是否报告使用错误,或者是否发生灾难性失败:
向 groovy 纯粹主义者致歉 - groovy 不是我的事,所以我确信这可以改进 - 请告诉我。有一个已知的漏洞:如果 pylint 仅检测到“致命”类型的错误(位 0)并且没有任何其他类型的问题(位 1-4 未设置),则此代码将错误地引发异常。但我的代码标记了大量问题,所以这对我来说不是问题。对于具有高超技术的人来说,修复(?解析错误消息?)可能是微不足道的。
I agree with @dmeister, but with pipeline code (Jenkinsfile) I suggest a try/catch and then parsing the error. This way you can determine if you're just getting status bits from pylint (see the Pylint docs), whether pylint reports a usage error, or whether there was a catastrophic fail:
Apologies to groovy purists - groovy isn't my thing, so I'm sure this can be improved on - let me know. There is one known hole: if pylint detects only "fatal"-type errors (bit 0) and no other issues of any kind (bits 1-4 are not set) then this code will incorrectly throw an exception. But my code flags tons of issues, so that's not a problem for me. The fix (?parse error msg?) might be trivial for someone with groovy chops.
pylint 给出的不是零退出,但没有明显的错误消息。您可能需要跟踪以查看哪个文件 pylint 失败。并查看文件。
对我来说,我添加一个带有 init.py 文件的空目录,并且 pylint 给出相同的错误
The pylint give not zero exit, but without obviously error message. you may need to trace to see which file pylint got failed. and take a look in the file.
For me, I add an empty directory with init.py file, and pylint give same error
您也可以简单地放置一个
shell 命令行中的 。通过检查 pylint 的结果,Pylint 插件无论如何都会使构建失败。
You can also simply put a
in the shell cmdline. The Pylint plugin will fail the build anyway by checking the result of pyllint.
在 Pylint 1.9.3 中,有一个
--exit-zero
标志。https://github.com/PyCQA/pylint/blob/1.9/ChangeLog#L47
In Pylint 1.9.3, there is a
--exit-zero
flag.https://github.com/PyCQA/pylint/blob/1.9/ChangeLog#L47
即使仅发现一个小的警告问题,Pylint 也有返回非零退出代码的令人不愉快的行为。仅当一切正常时,才会返回 0(请参阅手册页)。
由于非零代码通常表示错误,因此 Jenkins 构建失败。
我看到有两种方法可以克服这个问题:
Pylint has the unpleasant behavior to return a non-zero exit code even only if a small warning issue was found. Only when everything was fine, 0 is returned (see man page).
As usually a non-zero code denotes an error, Jenkins fails the build.
I see two ways to overcome this:
看来您的 pylint 执行退出时状态为非零(缺少脚本、错误选项...),也许您退出脚本时引发异常或
sys.exit(something_else_than_zero)
it seems that your pylint execution exit with a non-zero status (missing script, bad options...), maybe you exit the script with an exception raised or a
sys.exit(something_else_than_zero)
最近的 rylint 有不调用 sys exit 的选项
Recent rylint have option for not calling sys exit