0

我有这个 Jenkins 管道包含上游和下游作业,一旦请求的输入被批准/接受,我想通过调度它(cron/schedule the build)来运行下游作业。有人可以帮我这样做吗?

我尝试添加triggers下游作业,并Build periodically with parameters在管道中添加了选项。但是当上游作业构建成功时,下游作业就会运行。

上游工作:

pipeline {
    agent { any }

    stages {

        stage('Stage with input') {
            steps {
                script {
                    timeout(time: 24, unit: 'HOURS') {
                        userInput = input( id: 'Proceed', message: 'Test', parameters: [[$class: 'BooleanParameterDefinition', defaultValue: true, description: '', name: 'Please select the checkbox to approve this request']])
                        echo 'userInput: ' + userInput
                    }
                }
            }
        }

        stage('Trigger downstream Job') {
            steps {
                script {
                    def removalJob = build job: 'test2', propagate: false
                    parameters: [
                        [$class: 'StringParameterValue', name: 'FROM_BUILD', value: "${BUILD_NUMBER}"],
                        [$class: 'BooleanParameterValue', name: 'IS_READY', value: true]
                    ]

                    if (removalJob.result != "SUCCESS") {
                        echo "Build Status: ${removalJob.result}"
                    }
                }
            }
        }
    }
}

下游工作:

pipeline {
    agent { any }
    
    triggers { cron('H 16 9 10 6') }
    
    parameters {
        string(name: 'FROM_BUILD', defaultValue: '', description: 'Build Source')
        booleanParam(name: 'IS_READY', defaultValue: false, description: 'Is ready to build?')
    }

    stages {
        stage('Removal') {
            steps {
                echo "Removing Dirs from ${params.FROM_BUILD}"
            }
        }
    }
}
4

0 回答 0