Issue
- When a new GitHub Organization job is created, all repos are scanned and builds are triggered right away. Is there any way to prevent these automatic builds?
- I want to control whether a stage should be executed or not based on the triggered events.
Environment
- CloudBees CI (CloudBees Core)
- CloudBees CI (CloudBees Core) on modern cloud platforms - Managed Master
- CloudBees CI (CloudBees Core) on traditional platforms - Client Master
- CloudBees Jenkins Enterprise
- CloudBees Jenkins Enterprise - Managed Master
- CloudBees Jenkins Platform - Client Master
- CloudBees Jenkins Distribution
- Jenkins LTS
Resolution
The best way is to install Branch API 2.3.0 and Basic Branch Build Strategies 1.3.0. A new option is added to skip initial build on branch indexing:
If you can’t install the plugins for some reason, go to the GitHub Org configuration, clear the field Branch names to build automatically
.
After saving the job, you can add .*
to re-enable builds.
Workaround
You can also control when a stage should be executed. In the following example, the deployment stage is skipped unless the build is triggered by a Github push event.
pipeline {
agent none
stages {
stage('Example Build') {
steps {
echo 'Hello World'
}
}
stage('Example Deploy') {
when {
expression {
currentBuild.buildCauses.toString().contains("Push event to branch")
}
}
steps {
echo 'Deploying'
}
}
}
}
Tested product/plugin versions
-
Branch API 2.3.0
-
Basic Branch Build Strategies 1.3.0
-
GitHub Branch Source 2.4.1
0 Comments