I have a Multi branch pipeline project in Jenkins. I want to disable a branch while it is listed in pipeline project. I can add an exception to surpass scm triggering. But I want to disable all the triggering including manual triggering. If I used "Disable this project" under "Build triggers" in job created for a branch, that option is not selected when I reload the page(There are no save/apply buttons which is available for single branch pipelines). It only keeps follwing configuration that was configured in Jenkinsfile.
pipelineTriggers([
snapshotDependencies(),
]),
Are there any way to specify "Disable this project" in Jenkinsfile
True, you cannot disable the project from Jenkins Job as multibranch pipeline doesn't give control to change the settings from the job.
Two ways to stop your branch from building.
1) Disable the Branch
To get control of the settings, go to PROJECT(project you want to modify the settings) > Configure > Projects( enable advanced settings)
Enter the branch in "Exclude branch" and save the settings.
2) Rename Jenkinsfile
If you don't have control of the project settings, the easy way is to rename the Jenkinsfile in the project/branch.
This configuration will define to trigger a build if a branch/project has "Jenkinsfile" in it. Hence, renaming it will not trigger a build.
Hope this helps..
UPDATE : AFAIK, you can't disable the project from Jenkisfile, but as workaround you can configure the cronjob as follows:
properties([pipelineTriggers([cron('')])])
If configuration is not available in cron, the build will not trigger at all.
You can do something like this:
stages {
stage('Build') {
when {
not {
branch 'master'
}
}
steps {
...
}
}
}
Which isn't quite the same as not running the pipeline at all, but at least, it runs very quickly, and doesn't actually do the build, which is useful to have it not fail - say, if you are using a maven / gitflow pattern, where the master branch should not be built more than once, since the deployment would fail...
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