得之我幸 失之我命

when someone abandons you,it is him that gets loss because he lost someone who truly loves him but you just lost one who doesn’t love you.

让 Jenkins 忽略 sh 的执行失败

19 年开始接触 Jenkins,但是并没有跟 jf 有过多的交道,今年又碰到了它,并且和 jf 有了初步的接触,于是问题也是接踵而来,比如今天讨论的这个问题:在 jf 中执行 shell 脚本,当 shell 脚本遇到错误的时候,Jenkins 会忽略后续所有的步骤,为啥?咋办?

为啥?

默认情况下,Jenkins 采取 /bin/sh -xe 这种方式,-x 将打印每一个命令,另一个选项 -e,则是当任何命令以非零值(当任何命令失败时)退出代码时,会导致 shell 立即停止运行脚本。而 Jenkins 通过步骤的返回值确定步骤的成功/失败,对于 shell 的情况,以非零状态代码退出的脚本将导致该步骤失败并出现异常

咋办?

  1. 在脚本中加入 #!/bin/sh,避免 Jenkins 默认使用 -xe 执行

  2. 在脚本中加入 set +e,禁用 Jenkins 的默认 -e

  3. 如果是多行脚本,在脚本最后设置返回值,如果是单行脚本,直接 command1 || command2(command2 为返回值为 0 的语句)

  4. 步骤中加入 returnStatus: true

be yourself, everyone else is already taken.