Jenkinsfile管道,返回警告但不会失败

s27*_*840 5 jenkins jenkins-pipeline

有没有办法在声明性管道步骤中不失败,而是显示警告?目前,我通过|| exit 0在sh命令行的末尾进行添加来规避它,因此它始终退出正常。

当前示例:

sh 'vendor/bin/phpcs --report=checkstyle --report-file=build/checkstyle.xml --standard=phpcs.xml . || exit 0'

我觉得应该有更好的方法吗?您如何控制返回的结果,以便用户在不深入浏览结果日志的情况下也知道没有阻塞/失败的情况?

谢谢

编辑:

因此,到目前为止,我已经能够将其标记为不稳定。在《蓝海》中,它只是将每个阶段标记为不稳定,因此您必须仔细研究才能找到它。我是否在尝试做不可能的事情(但感觉应该可以做到)?

另外,它现在只是在“蓝天”的标题中将其显示为“ Shell脚本”,而不显示正在运行的命令,因此您甚至不知道扩展每个命令的作用。

script {
  def RESULT = sh returnStatus: true, script: 'vendor/bin/phpcs --report=checkstyle --report-file=build/checkstyle.xml --standard=phpcs.xml .'
  if ( RESULT != 0 ) {
    currentBuild.result = 'UNSTABLE'
  }
}
Run Code Online (Sandbox Code Playgroud)

重新将其标记为黄色/不稳定:刚发现这说明我不会生气。几年的讨论没有任何进展:( https://issues.jenkins-ci.org/browse/JENKINS-39203

只是现在在Blue Ocean视图上显示“ Shell脚本”就可以了:我将继续玩一些游戏,看看我是否对|| exit 0Script块更好,还是使用echo来显示一些有用的信息。

msa*_*msa 8

仅供参考:JENKINS-39203同时已得到解决。

我们不使用设置,而是currentBuild.result = 'UNSTABLE'使用相应的基本管道步骤unstable,它也接受一条消息:

unstable("There are Checkstyle issues")
Run Code Online (Sandbox Code Playgroud)


Fid*_*del 3

您可以在 jenkins 本身的 下找到任何步骤的选项http://jenkins-url/pipeline-syntax/。sh 和 returnStatus: true 可以用来实现你的目标。

sh returnStatus: true, script: 'ls -2' # returnStatus: true, just set $? but not fail the execution
Run Code Online (Sandbox Code Playgroud)

下面粘贴了管道语法页面的屏幕截图: 管道语法页面的屏幕截图