What if Jenkins could magically find and build every branch you create without you lifting a finger?
Why Branch discovery configuration in Jenkins? - Purpose & Use Cases
Imagine you have many branches in your code repository, and you want Jenkins to build each one automatically.
Without branch discovery, you have to manually add each branch to Jenkins jobs.
Manually tracking branches is slow and error-prone.
New branches might be missed, and deleted branches might still trigger builds.
This wastes time and causes confusion.
Branch discovery configuration lets Jenkins automatically find all branches in your repository.
It keeps track of new, changed, or deleted branches without manual work.
Create job for branch1 Create job for branch2 Create job for branch3
Enable branch discovery in Jenkins job configuration
Jenkins auto-detects all branchesYou can focus on coding while Jenkins handles building all your branches automatically and reliably.
A team creates feature branches daily; with branch discovery, Jenkins builds each new feature branch without extra setup.
Manual branch setup is slow and error-prone.
Branch discovery automates branch detection in Jenkins.
This saves time and ensures all branches are built correctly.
Practice
What is the main purpose of branch discovery in Jenkins?
Solution
Step 1: Understand branch discovery concept
Branch discovery is designed to find all branches automatically in a source code repository.Step 2: Identify the purpose in Jenkins
Jenkins uses branch discovery to keep builds updated without manual intervention.Final Answer:
To automatically find and build all branches in a repository -> Option CQuick Check:
Branch discovery = automatic branch finding [OK]
- Thinking branch discovery requires manual branch selection
- Confusing branch discovery with branch deletion
- Assuming branch discovery merges branches
Which strategyId value in Jenkins branch discovery configuration finds all branches including PRs?
Solution
Step 1: Recall strategyId meanings
In Jenkins, strategyId 3 means discover all branches including pull requests.Step 2: Match strategyId to description
StrategyId 1 is for only branches, 2 is for branches and PRs from origin, 3 includes all branches and PRs, 4 is for PRs only.Final Answer:
3 -> Option DQuick Check:
strategyId 3 = all branches + PRs [OK]
- Confusing strategyId 1 with including PRs
- Using strategyId 4 which only finds PRs
- Assuming strategyId 2 includes PRs
Given this Jenkins branch discovery snippet:
{"strategyId": 1}Which branches will Jenkins discover?
Solution
Step 1: Understand strategyId 1 meaning
StrategyId 1 means discover only branches, excluding pull requests.Step 2: Apply to the snippet
The snippet uses strategyId 1, so Jenkins finds only normal branches, not PRs.Final Answer:
Only branches that are not pull requests -> Option AQuick Check:
strategyId 1 = branches only [OK]
- Assuming strategyId 1 includes PRs
- Thinking strategyId 1 finds no branches
- Confusing strategyId 1 with strategyId 3
You configured Jenkins with {"strategyId": 5} for branch discovery. What is the likely result?
Solution
Step 1: Check valid strategyId values
Valid strategyId values are 1, 2, 3, and 4. 5 is invalid.Step 2: Predict Jenkins behavior on invalid strategyId
Jenkins will likely throw an error or ignore the invalid value, causing no discovery.Final Answer:
Jenkins throws a configuration error or ignores the setting -> Option BQuick Check:
Invalid strategyId = error or ignore [OK]
- Assuming strategyId 5 works like 3 or 4
- Expecting Jenkins to discover branches anyway
- Ignoring configuration errors
You want Jenkins to build only branches that start with feature/ and ignore others. Which branch discovery configuration should you use?
Solution
Step 1: Choose strategyId for branches only
StrategyId 1 discovers only branches (excluding PRs), suitable for filtering branches.Step 2: Apply branch filter for prefix
Adding a filter for branches starting with 'feature/' limits builds to those branches only.Final Answer:
Use {"strategyId": 1} with an additional branch filter for feature/* -> Option AQuick Check:
strategyId 1 + filter = feature branches only [OK]
- Using strategyId 3 without filters builds all branches and PRs
- Disabling filters causes all branches to build
- Using strategyId 4 only finds PRs, not branches
Ready to prove it?
Pass the test and this pattern moves unknown
