OK,我有一个.sh脚本,这几乎是一切Jenkins应该做的:
>检查来自SVN的源
>构建项目
>部署项目
>清理后自己
所以在Jenkins中,我只需要通过在Execute Shell命令中运行脚本来“构建”项目。
脚本被运行(源被下载,项目是构建/部署),但然后它将构建标记为失败:
构建步骤“执行shell”将标记为生成为失败
即使脚本成功运行!我试着关闭脚本:
> exit 0(仍然将其标记为失败)
>退出1(将其标记为失败,如预期)
>根本没有退出命令(将其标记为失败)
什么时候,如何以及为什么Execute Shell将我的构建标记为失败?
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”
简单的答案是:Jenkin的Execute Shell构建步骤的last命令的退出代码是什么决定了构建步骤的成功/失败。 0 – 成功,其他 – 失败。
注意,这是确定构建步骤的成功/失败,而不是整个作业运行。整个作业运行的成功/失败可能进一步受到多个构建步骤以及后构建操作和插件的影响。
你提到了Build步骤“Execute shell”将build标记为失败,所以我们将只关注一个单独的构建步骤。如果您的执行shell构建步骤只有一行调用您的shell脚本,那么您的shell脚本的退出代码将确定构建步骤的成功/失败。如果你有更多的行,在你的shell脚本执行后,然后仔细检查他们,因为它们是可能会导致失败。
最后,有一个在这里阅读Jenkins Build Script exits after Google Test execution.它不直接与你的问题,但注意一部分关于Jenkins启动执行Shell构建步骤,作为shell脚本与/ bin / sh -xe
-e意味着shell脚本将会失败地退出,即使只有一个命令失败,即使您对该命令进行错误检查(因为脚本在您进行错误检查之前就会退出)。这与正常执行shell脚本相反,shell脚本通常打印失败命令的错误消息(或将其重定向到null并通过其他方式处理它),然后继续。
为了避免这种情况,将set e添加到shell脚本的顶部。
因为你说你的脚本做了它应该做的所有事情,有机会是失败的命令是在脚本的结尾处。也许是最后的回声?还是文物的副本?没有看到完整的控制台输出,我们只是猜测。
请发布作业运行的控制台输出,最好是shell脚本本身,然后我们可以告诉你究竟哪一行是失败的。