Can anyone help me to answer this question?
1 Replies
@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'
}
}
}
}