更新时间:2021-12-28 07:11:42
默认情况下,Jenkins 使用标志 -xe
启动 shell 脚本.-x
启用额外的日志记录.-e
如果里面的任何命令返回非零退出状态,则使脚本退出.要重置标志,我建议两个选项:
By default Jenkins starts shell scripts with flags -xe
. -x
enables additional logging. -e
makes the script exit if any command inside returns non-zero exit status. To reset a flag I'd suggest two options:
set +x
.-x
的情况下传递自定义 shebang 行:sh('#!/bin/sh -e
' + 'echo shellscript.sh arg1 arg2')
set +x
in the body of your script.-x
: sh('#!/bin/sh -e
' + 'echo shellscript.sh arg1 arg2')
至于第二个选项,您可以为方便定义一个包装函数,该函数将在脚本前面加上自定义 shebang,然后调用 sh
As for the second option you can define a wrapper function for convenience which will prepend the script with custom shebang and then call sh
def mysh(cmd) {
sh('#!/bin/sh -e
' + cmd)
}