I'm working with a Multi-Branch Jenkins build, of which I want the develop branch to build periodically every two weeks and leave the master branch manual.
Our pipelines are pipelines as code, so I cannot set the config for the desired branches.
I'd like to build our develop branch once every 2 weeks on a sunday, so far I have found some different things.
Right now I've come to this schedule:
triggers {
cron('00 12 /2 7')
}
But I do not know how to make it branch specific. I'm trying this right now to see if it works, should trigger a develop build every 5 mins or break.
triggers {
when (env.BRANCH_NAME == 'develop') {
cron('H/5 * * * *')
}
}
when is not allowed in the triggers block.
I have found a 'solution' on the Jenkins jira which is this:
String cron_string = BRANCH_NAME == "develop" ? "00 12 /2 7" : ""
pipeline {
agent none
triggers { cron(cron_string) }
stages {
// do something
}
}
The Multibranch Pipeline project type enables you to implement different Jenkinsfiles for different branches of the same project. In a Multibranch Pipeline project, Jenkins automatically discovers, manages and executes Pipelines for branches which contain a Jenkinsfile in source control.
Adding a Jenkins triggerSelect a Jenkins master from the Master drop-down menu, then select a job from the Job drop-down. Add a property file, if desired. See the property files section of the Pipeline Expression Guide for more information about how to specify and use property files.
A multi-branch pipeline project always includes a Jenkinsfile in its repository root. Jenkins automatically creates a sub-project for each branch that it finds in a repository with a Jenkinsfile . Multi-branch pipelines use the same version control as the rest of your software development process.
Head over to your Jenkins instance and create a new item. Enter a name for the job, and select the “Multibranch Pipeline” option at the end of the screen. Then, click on the OK button. In the next screen, go to the “Branch sources” tab, click on the “Add source” button, and choose “Git” from the dropdown menu.
I have found a 'solution' on the Jenkins jira which is this:
String cron_string = BRANCH_NAME == "develop" ? "00 12 /2 7" : ""
pipeline {
agent none
triggers { cron(cron_string) }
stages {
// do something
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With