Jenkins Build Pipeline Scheduled Trigger

前端 未结 6 773
独厮守ぢ
独厮守ぢ 2020-12-13 06:15

How can a build pipeline be scheduled to execute at a certain time of the night just like a regular job can be?

6条回答
  •  死守一世寂寞
    2020-12-13 06:40

    If you want to run the job periodically for a specific branch using a multibranch pipeline you can do this in your Jenkinsfile:

    def call(String cronBranch = 'master') {
    
        // Cron job to be run from Monday to Friday at 10.00h (UTC)
        String cronString = BRANCH_NAME == cronBranch ? "0 10 * * 1-5" : ""
    
        pipeline {
            agent any
    
            triggers {
                cron(cronString)
            }
            stages {
                stage('My Stage') {
                    //Do something
                }
            }
        }
    }
    

    You need to run this job manually the first time in order to be added.

提交回复
热议问题