如何/何时执行shell标志着构建在詹金斯失败? [英] How/When does Execute Shell mark a build as failure in Jenkins?

查看:3199
本文介绍了如何/何时执行shell标志着构建在詹金斯失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

恐怖故事,我发现同时寻找答案这一个...

The horror stories I found while searching for an answer for this one...

OK,我有pretty钱?詹金斯都应该做一个.SH脚本:

OK, I have a .sh script which pretty much does everything Jenkins supposed to do:


  • 从SVN检出源

  • 构建项目

  • 部署项目

  • 后本身
  • 清洗

因此​​,在詹金斯我只有'建设项目通过运行在执行shell命令脚本。
 该脚本运行(来源下载,该项目是构建/部署),但是它标志着构建是失败的:
构建步骤执行shell标记建设成为失败
即使脚本已成功运行!我试图关闭脚本:

So in Jenkins I only have to 'build' the project by running the script in an Execute Shell command. The script is ran (the sources are downloaded, the project is build/deploy) but then it marks the build as a failure: Build step 'Execute shell' marked build as failure Even if the script was successfully ran! I tried closing the script with:


  • 退出0(还是将其标记为失败)

  • 1号出口(标记为失败,如预期)

  • 在完全没有exit命令(标记为失败)

何时,如何以及为什么执行shell记住我作为构建失败?

When, how and why does Execute Shell mark my build as a failure?

推荐答案

首先第一件事,将鼠标悬停在下方的灰色区域。没有答案的一部分,但绝对有说:

First things first, hover the mouse over the grey area below. Not part of the answer, but absolutely has to be said:

如果你有一个shell脚本,做检出,构建,部署所有的本身,那你为什么要使用詹金斯?您前述,使得它是什么了詹金斯的所有功能。 您可能也有cron或一个SVN post-commit钩子调用脚本直接。詹金斯进行SVN结帐本身是至关重要的。它允许建立,只有当有变化(或定时或手动,如果你preFER)被触发。它跟踪变化之间架起。它显示了这些变化,所以你可以看到它的构建是其中设置的变化。它的电子邮件时,他们的变化引起的成功或失败的版本(再次,如配置为您preFER)提交者。当他们的补丁修复的失败构建它会通过电子邮件提交者。而越来越多。詹金斯归档文物也使它们可用,每身材,直客詹金斯。虽然没有SVN结帐至关重要,这是又一次的什么使得它詹金斯的一个组成部分。同样与部署。除非你有一个单一的环境,部署通常发生于多种环境。詹金斯可以跟踪哪些环境的特定版本(与特定的一组SVN的变化)被部署它,通过使用促销。您前述这一切。这听起来像你被告知你必须使用詹金斯,但你真的不想要了,你正在做它只是为了让你的老板把你回来了,只是把一个对号是的,我用詹金斯

If you have a shell script that does "checkout, build, deploy" all by itself, then why are you using Jenkins? You are foregoing all the features of Jenkins that make it what it is. You might as well have a cron or an SVN post-commit hook call the script directly. Jenkins performing the SVN checkout itself is crucial. It allows the builds to be triggered only when there are changes (or on timer, or manual, if you prefer). It keeps track of changes between builds. It shows those changes, so you can see which build was for which set of changes. It emails committers when their changes caused successful or failed build (again, as configured as you prefer). It will email committers when their fixes fixed the failing build. And more and more. Jenkins archiving the artifacts also makes them available, per build, straight off Jenkins. While not as crucial as the SVN checkout, this is once again an integral part of what makes it Jenkins. Same with deploying. Unless you have a single environment, deployment usually happens to multiple environments. Jenkins can keep track of which environment a specific build (with specific set of SVN changes) is deployed it, through the use of Promotions. You are foregoing all of this. It sounds like you are told "you have to use Jenkins" but you don't really want to, and you are doing it just to get your bosses off your back, just to put a checkmark "yes, I've used Jenkins"

简短的回答是:出口code 最后的詹的执行shell 建设步骤的命令是什么决定了的成功/失败构建步骤即可。 0 - 致胜,别的什么 - 失败。
请注意,这是确定的的成功/失败生成步骤,而不是整个的作业运行。整个作业运行的成功/失败还可以通过多个构建步骤受到影响,后期生成操作和插件。

The short answer is: the exit code of last command of the Jenkin's Execute Shell build step is what determines the success/failure of the Build Step. 0 - success, anything else - failure. Note, this is determining the success/failure of the build step, not the whole job run. The success/failure of the whole job run can further be affected by multiple build steps, and post-build actions and plugins.

您已经提到生成步骤执行shell标记为构建失败,所以我们将只集中在一个单一的生成步骤。如果您的执行shell 生成步骤只有调用你的shell脚本,那么你的shell脚本的退出code将确定构建步骤的成功/失败一行。如果您有更多的线条,您的shell脚本的执行,然后仔细检查它们,因为它们可能会造成失败的人。

You've mentioned Build step 'Execute shell' marked build as failure, so we will focus just on a single build step. If your Execute shell build step only has a single line that calls your shell script, then the exit code of your shell script will determine the success/failure of the build step. If you have more lines, after your shell script execution, then carefully review them, as they are the ones that could be causing failure.

最后,有一个在这里阅读 <一个href=\"http://stackoverflow.com/questions/13400445/jenkins-build-script-exits-after-google-test-execution/13404608#13404608\">Jenkins建立谷歌测试执行后脚本退出 。它不直接关系到你的问题,但要注意对詹金斯的一部分推出的执行shell 生成步骤,与 / bin / sh的-xe

Finally, have a read here Jenkins Build Script exits after Google Test execution. It is not directly related to your question, but note that part about Jenkins launching the Execute Shell build step, as a shell script with /bin/sh -xe

-e 表示shell脚本将退出失败,哪怕只是1命令失败,均匀如果你错误检查该命令(因为脚本退出它到达你的错误检查之前)。这违背了shell脚本的正常执行,通常打印为失败的命令错误信息(或重定向为null,并通过其他方式处理它),然后继续。

The -e means that the shell script will exit with failure, even if just 1 command fails, even if you do error checking for that command (because the script exits before it gets to your error checking). This is contrary to normal execution of shell scripts, which usually print the error message for the failed command (or redirect it to null and handle it by other means), and continue.

要规避这一点,添加组+ E 你的shell脚本的顶端。

To circumvent this, add set +e to the top of your shell script.

既然你说你的脚本做一切应该做的事,机会是失败的命令是在脚本的最后的地方。也许最后的回音?或文物复制的地方?没有看到完整的控制台输出,我们都只是猜测。

Since you say your script does all it is supposed to do, chances are the failing command is somewhere at the end of the script. Maybe a final echo? Or copy of artifacts somewhere? Without seeing the full console output, we are just guessing.

请发布作业运行的控制台输出,和preferably shell脚本本身也一样,然后我们可以确切地告诉你哪一行是失败。

Please post the job run's console output, and preferably the shell script itself too, and then we could tell you exactly which line is failing.

这篇关于如何/何时执行shell标志着构建在詹金斯失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆