Build Multi Branch Periodically
If you use a declarative style Pipeline and only want to trigger the build on a specific branch you can do something like this:
String cron_string = BRANCH_NAME == "master" ? "@hourly" : ""
pipeline { agent none triggers { cron(cron_string) } stages { // do something }}
Found on Jenkins Jira
If you are using a declarative style Jenkinsfile then you use the triggers directive.
pipeline { agent any triggers { cron('H 4/* 0 0 1-5') } stages { stage('Example') { steps { echo 'Hello World' } } }}
This is working for me:
pipeline { triggers { cron(env.BRANCH_NAME == 'development' ? 'H */12 * * *' : '') }}
See more in this article
Sources:
- https://stackoverflow.com/questions/39168861/build-periodically-with-a-multi-branch-pipeline-in-jenkins