且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在詹金斯管道构建日志中禁用命令输出

更新时间: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:

  1. 在脚本正文中调用 set +x.
  2. 在没有 -x 的情况下传递自定义 shebang 行:sh('#!/bin/sh -e ' + 'echo shellscript.sh arg1 arg2')
  1. Call set +x in the body of your script.
  2. Pass custom shebang line without -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)
}