Techiio-author
Started by sumit JalanMay 28, 2021

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

11 VIEWES 3 LIKES 0 DISLIKES SHARE
3 LIKES 0 DISLIKES 11 VIEWES SHARE

Can anyone help me to answer this question?

1 Replies

Techiio-commentatorAbhishek Jalan replied a year 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
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance