且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在脚本管道中发布等价的内容?

更新时间:2023-10-19 20:50:04

对于脚本化管道,所有内容都必须以编程方式编写,并且大部分工作都在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