gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 21:04:08 29 4
gpt4 key购买 nike

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

当前示例:
sh 'vendor/bin/phpcs --report=checkstyle --report-file=build/checkstyle.xml --standard=phpcs.xml . || exit 0'
我觉得应该有更好的方法来做到这一点?您如何控制返回的结果,以便用户在不查看结果日志但不阻塞/失败的情况下知道?

谢谢

编辑:

所以我已经走了这么远才能将其标记为不稳定。在 Blue Ocean 中,它只是将每个阶段标记为不稳定,您必须深入挖掘才能找到它。我是否正在尝试做不可能的事情(但感觉我应该能够做到)?

此外,它现在只是在 Blue Sky 的标题中将其显示为“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'
}
}

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

现在它只是在 Blue Ocean View 上显示“Shell 脚本”:我会去玩更多游戏,看看我是否能更好地使用 || exit 0或脚本块并使用 echo 显示一些有用的信息。

最佳答案

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

sh returnStatus: true, script: 'ls -2' # returnStatus: true, just set $? but not fail the execution

下面粘贴了管道语法页面的屏幕截图:
Screenshot from pipeline-syntax page

关于Jenkinsfile 管道,返回警告但不会失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50835118/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com