无法理解 `sh !` 在 Jenkins 管道代码中的作用

unable to understand what `sh !` does inside a Jenkins pipeline code

我有一个 Jenkins 管道代码

stages {
    stage('Monitoring logs') {
       steps {
          script {
              sh '! grep "wow" output.log
                 }
              }
          }
      }

有人可以解释这部分代码的作用 -> sh '! grep "wow" output.log' 以及它对执行或管道执行状态有什么影响,如果在中找到“wow”字符串output.log?

我知道 grep "wow" output.log 会在 output.log 中搜索“wow”字符串,但我不知道 sh '! grep "wow" output.log' 会做什么?

    如果 output.log 包含 wow
  1. grep "wow" output.log 成功(退出 0),否则失败(退出非 0)。

  2. ! negates the exit code(0变为1;非0变为0)。

  3. Jenkins’ sh function 运行 shell 脚本并在非 0 退出代码上抛出异常,这将使管道失败。*

因此,如果 output.log 包含 wow,管道将失败。

* 通过使用 -e 选项。