我想为Jenkins添加一个命令行脚本作为构build过程的一部分。 如果成功的话,这个命令行脚本将会以一个错误代码0退出,如果失败,它将退出666 。 如果脚本失败,我希望停止构build。
是否有可能使用Jenkins做到这一点? 如果这样怎么样?
您的bash构build脚本可以在运行testing之前set -e 。
如果在构build过程中有一个非零的退出状态, set -e会导致Jenkins停止构build。 在项目configuration的“Execute Shell”框中,您可能会看到如下所示的内容:
set -e yourcommand1 yourcommand2
这里是关于bash选项的一些文档 。
您需要小心退出255以上的代码。退出代码必须在0-255的范围内。 0意味着成功另一个1-255是错误代码。 您还必须避免具有一定含义的保留错误代码 。
cmp@cmp-dev:~$ bash --version GNU bash, version 4.1.5(1)-release (x86_64-pc-linux-gnu) Copyright (C) 2009 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
这里是666号出口:
$ bash $ exit 666 exit $ echo $? 154
它在255:
$ bash $ exit 256 exit $ echo $? 0
坚持255下,并避免保留错误代码 (更好的魔鬼,你知道吗?)