Started by sumit JalanMay 28, 2021

Open
How Jenkins knows when to execute a Scheduled job/pipeline and how it is triggered?

9 VIEWES 3 LIKES 0 DISLIKES SHARE
3 LIKES 0 DISLIKES 9 VIEWES SHARE

Can anyone help me to answer this question?

1 Replies

Abhishek Jalan replied 3 months ago0 likes0 dislikes

@Sumit, 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
            }
        }
    }
}

or complete Example (taken from docs) Ref: https://jenkins.io/doc/book/pipeline/syntax/#triggers

pipeline {
    agent any
    triggers {
        cron('H */4 * * 1-5')
    }
    stages {
        stage('Example') {
            steps {
                echo 'Hello World'
            }
        }
    }
}
You must be Logged in to reply
Trending Categories
95
Software18
DevOps35
Frontend Development19
Backend Development17
Server Administration13
Linux Administration16
Data Center20
Sentry22
Terraform19
Ansible19
Docker19
Penetration Testing12
Kubernetes13
NGINX14
JenkinsX16
Jenkins20
SSL10
Ethical-Hacking10
Python12
NodeJs15
RedHat14
Github18
AngularJs15
Google Cloud Platform (GCP)6
SonarQube13
Amazon Web Service (AWS)13
VMware17
Blockchain12
Snipe-IT7