0
0
Jenkinsdevops~10 mins

Branch discovery configuration in Jenkins - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Branch discovery configuration
Start Jenkins Job Setup
Enable Branch Discovery
Scan Repository Branches
Apply Filters (if any)
List Discovered Branches
Trigger Builds for Selected Branches
End
This flow shows how Jenkins scans and discovers branches in a repository to decide which branches to build.
Execution Sample
Jenkins
properties([
  pipelineTriggers([]),
  branchSources([gitHub({
    repoOwner: 'user',
    repository: 'repo',
    traits: [branchDiscovery()]
  })])
])
This Jenkins pipeline snippet configures branch discovery for a GitHub repository.
Process Table
StepActionEvaluationResult
1Start job setupN/AJob configuration begins
2Enable branch discovery traitbranchDiscovery() trait addedJenkins will scan branches
3Scan repositoryFetch all branches from repoBranches list retrieved
4Apply filtersNo filters appliedAll branches included
5List discovered branchesBranches: main, dev, feature1Branches ready for build
6Trigger buildsBuilds triggered for each branchBuilds started
7EndAll branches processedJob setup complete
💡 All branches discovered and builds triggered; job setup ends
Status Tracker
VariableStartAfter Step 3After Step 5Final
branchesList[][main, dev, feature1][main, dev, feature1][main, dev, feature1]
buildsTriggered0033
Key Moments - 2 Insights
Why does Jenkins need to scan branches before building?
Jenkins scans branches to know which branches exist and should be built. Without scanning (see step 3 in execution_table), Jenkins cannot discover new or updated branches.
What happens if filters are applied during branch discovery?
Filters limit which branches Jenkins includes for building. In the execution_table step 4, no filters means all branches are included. If filters were applied, some branches might be excluded.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step does Jenkins retrieve the list of branches?
AStep 2
BStep 3
CStep 5
DStep 6
💡 Hint
Check the 'Action' and 'Result' columns for branch retrieval in the execution_table
According to variable_tracker, how many builds are triggered after step 5?
A0
B1
C3
D5
💡 Hint
Look at the 'buildsTriggered' row under 'After Step 5' in variable_tracker
If a filter excluded the 'feature1' branch, how would the branchesList change after step 5?
A[main, dev]
B[]
C[main, dev, feature1]
D[feature1]
💡 Hint
Filters reduce branches included; see explanation in key_moments about filters
Concept Snapshot
Branch discovery in Jenkins:
- Enable branchDiscovery() trait in job config
- Jenkins scans repo branches
- Filters can include/exclude branches
- Discovered branches trigger builds
- Keeps CI updated with repo branches
Full Transcript
Branch discovery configuration in Jenkins involves enabling a trait that scans the repository for all branches. Jenkins fetches the list of branches, applies any filters if configured, and then triggers builds for the selected branches. This process ensures Jenkins knows which branches exist and keeps the build process up to date. The execution flow starts with job setup, enabling branch discovery, scanning branches, filtering, listing branches, triggering builds, and ending the setup. Variables like branchesList and buildsTriggered track the discovered branches and how many builds start. Filters can limit which branches are built. Understanding these steps helps beginners see how Jenkins manages multiple branches automatically.