Bird
Raised Fist0
Jenkinsdevops~10 mins

Branch discovery configuration in Jenkins - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to enable branch discovery in Jenkins Multibranch Pipeline.

Jenkins
branchSources {
  git {
    id('1234')
    remote('https://github.com/example/repo.git')
    [1]
  }
}
Drag options to blanks, or click blank then click option'
AbranchDiscovery { strategyId(2) }
BbranchDiscovery { strategyId(1) }
CbranchDiscovery { strategyId(3) }
DbranchDiscovery { strategyId(4) }
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong strategyId disables branch discovery.
2fill in blank
medium

Complete the code to configure Jenkins to discover pull requests from origin.

Jenkins
branchSources {
  git {
    id('5678')
    remote('https://github.com/example/repo.git')
    pullRequestDiscovery {
      [1]
    }
  }
}
Drag options to blanks, or click blank then click option'
AstrategyId(2)
BstrategyId(1)
CstrategyId(3)
DstrategyId(4)
Attempts:
3 left
💡 Hint
Common Mistakes
Using strategyId for fork PRs instead of origin PRs.
3fill in blank
hard

Fix the error in the branch discovery configuration to correctly discover branches.

Jenkins
branchSources {
  git {
    id('91011')
    remote('https://github.com/example/repo.git')
    branchDiscovery {
      [1]
    }
  }
}
Drag options to blanks, or click blank then click option'
AstrategyId(0)
BstrategyId(5)
CstrategyId(1)
DstrategyId(2)
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid strategyId causes Jenkins to ignore branches.
4fill in blank
hard

Fill both blanks to configure Jenkins to discover branches and pull requests from forks.

Jenkins
branchSources {
  git {
    id('121314')
    remote('https://github.com/example/repo.git')
    branchDiscovery {
      [1]
    }
    pullRequestDiscovery {
      [2]
    }
  }
}
Drag options to blanks, or click blank then click option'
AstrategyId(2)
BstrategyId(1)
CstrategyId(4)
DstrategyId(3)
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up strategy IDs for branch and PR discovery.
5fill in blank
hard

Fill all three blanks to configure Jenkins Multibranch Pipeline for branch discovery, origin PRs, and fork PRs.

Jenkins
branchSources {
  git {
    id('151617')
    remote('https://github.com/example/repo.git')
    branchDiscovery {
      [1]
    }
    pullRequestDiscovery {
      strategyId([2])
    }
    pullRequestDiscovery {
      strategyId([3])
    }
  }
}
Drag options to blanks, or click blank then click option'
AstrategyId(2)
B3
C4
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing strategy IDs for origin and fork PRs.

Practice

(1/5)
1.

What is the main purpose of branch discovery in Jenkins?

easy
A. To merge branches automatically before building
B. To manually select branches for building
C. To automatically find and build all branches in a repository
D. To delete old branches from the repository

Solution

  1. Step 1: Understand branch discovery concept

    Branch discovery is designed to find all branches automatically in a source code repository.
  2. Step 2: Identify the purpose in Jenkins

    Jenkins uses branch discovery to keep builds updated without manual intervention.
  3. Final Answer:

    To automatically find and build all branches in a repository -> Option C
  4. Quick Check:

    Branch discovery = automatic branch finding [OK]
Hint: Branch discovery means Jenkins finds branches automatically [OK]
Common Mistakes:
  • Thinking branch discovery requires manual branch selection
  • Confusing branch discovery with branch deletion
  • Assuming branch discovery merges branches
2.

Which strategyId value in Jenkins branch discovery configuration finds all branches including PRs?

easy
A. 4
B. 2
C. 1
D. 3

Solution

  1. Step 1: Recall strategyId meanings

    In Jenkins, strategyId 3 means discover all branches including pull requests.
  2. 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.
  3. Final Answer:

    3 -> Option D
  4. Quick Check:

    strategyId 3 = all branches + PRs [OK]
Hint: strategyId 3 includes all branches and PRs [OK]
Common Mistakes:
  • Confusing strategyId 1 with including PRs
  • Using strategyId 4 which only finds PRs
  • Assuming strategyId 2 includes PRs
3.

Given this Jenkins branch discovery snippet:

{"strategyId": 1}

Which branches will Jenkins discover?

medium
A. Only branches that are not pull requests
B. All branches including pull requests
C. Only pull request branches
D. No branches will be discovered

Solution

  1. Step 1: Understand strategyId 1 meaning

    StrategyId 1 means discover only branches, excluding pull requests.
  2. Step 2: Apply to the snippet

    The snippet uses strategyId 1, so Jenkins finds only normal branches, not PRs.
  3. Final Answer:

    Only branches that are not pull requests -> Option A
  4. Quick Check:

    strategyId 1 = branches only [OK]
Hint: strategyId 1 excludes PRs, finds only branches [OK]
Common Mistakes:
  • Assuming strategyId 1 includes PRs
  • Thinking strategyId 1 finds no branches
  • Confusing strategyId 1 with strategyId 3
4.

You configured Jenkins with {"strategyId": 5} for branch discovery. What is the likely result?

medium
A. Jenkins discovers all branches and PRs correctly
B. Jenkins throws a configuration error or ignores the setting
C. Jenkins discovers only pull requests
D. Jenkins discovers no branches but builds anyway

Solution

  1. Step 1: Check valid strategyId values

    Valid strategyId values are 1, 2, 3, and 4. 5 is invalid.
  2. Step 2: Predict Jenkins behavior on invalid strategyId

    Jenkins will likely throw an error or ignore the invalid value, causing no discovery.
  3. Final Answer:

    Jenkins throws a configuration error or ignores the setting -> Option B
  4. Quick Check:

    Invalid strategyId = error or ignore [OK]
Hint: Use only valid strategyId 1-4 to avoid errors [OK]
Common Mistakes:
  • Assuming strategyId 5 works like 3 or 4
  • Expecting Jenkins to discover branches anyway
  • Ignoring configuration errors
5.

You want Jenkins to build only branches that start with feature/ and ignore others. Which branch discovery configuration should you use?

hard
A. Use {"strategyId": 1} with an additional branch filter for feature/*
B. Use {"strategyId": 3} without any filters
C. Use {"strategyId": 2} and disable branch filtering
D. Use {"strategyId": 4} with a filter for feature/*

Solution

  1. Step 1: Choose strategyId for branches only

    StrategyId 1 discovers only branches (excluding PRs), suitable for filtering branches.
  2. Step 2: Apply branch filter for prefix

    Adding a filter for branches starting with 'feature/' limits builds to those branches only.
  3. Final Answer:

    Use {"strategyId": 1} with an additional branch filter for feature/* -> Option A
  4. Quick Check:

    strategyId 1 + filter = feature branches only [OK]
Hint: Combine strategyId 1 with branch filter for prefix [OK]
Common Mistakes:
  • 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
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard