在脚本化管道中发布等价物? [英] post equivalent in scripted pipeline?
本文介绍了在脚本化管道中发布等价物?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
与声明式管道相比,脚本式管道中post"的语法是什么?https://jenkins.io/doc/book/pipeline/syntax/#post一个>
What is the syntax of 'post' in scripted pipeline comparing to declarative pipeline? https://jenkins.io/doc/book/pipeline/syntax/#post
推荐答案
对于脚本化管道,一切都必须以编程方式编写,并且大部分工作都在 finally
块中完成:
For scripted pipeline, everything must be written programmatically and most of the work is done in the finally
block:
Jenkinsfile
(脚本流水线):
node {
try {
stage('Test') {
sh 'echo "Fail!"; exit 1'
}
echo 'This will run only if successful'
} catch (e) {
echo 'This will run only if failed'
// Since we're catching the exception in order to report on it,
// we need to re-throw it, to ensure that the build is marked as failed
throw e
} finally {
def currentResult = currentBuild.result ?: 'SUCCESS'
if (currentResult == 'UNSTABLE') {
echo 'This will run only if the run was marked as unstable'
}
def previousResult = currentBuild.getPreviousBuild()?.result
if (previousResult != null && previousResult != currentResult) {
echo 'This will run only if the state of the Pipeline has changed'
echo 'For example, if the Pipeline was previously failing but is now successful'
}
echo 'This will always run'
}
}
https://jenkins.io/doc/pipeline/tour/running-multiple-steps/#finishing-up
这篇关于在脚本化管道中发布等价物?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文