Jenkins Job DSL 在 postBuildScripts shell 中获取当前构建结果

Jenkins Job DSL get current build result in postBuildScripts shell

我需要在我的 Jenkins DSL 脚本中的 postBuildScripts shell 调用中获取当前构建执行的结果。就像 Jenkins 管道中的 ${currentBuild.currentResult} 具有以下值:SUCCESS、UNSTABLE 或 FAILURE

我已经搜索过 DSL 文档,但还没有找到任何解决方案。

我的代码是这样的:

postBuildScripts {
  steps {
    shell("""echo $CURRENT_BUILD_STATUS""")
  }
}

那么如何以最简单的方式获得此 $CURRENT_BUILD_STATUS

不幸的是,PostBuildScript 插件的文档缺少一些有趣的部分...

job('example') {
  publishers {
    postBuildScripts {
      steps {
        shell('echo $BUILD_RESULT')
      }
    }
  }
}