Chapter 22Lesson 03~145 minutes

Multibranch Pipelines, Branch Sources, Pull Request Discovery, Jenkinsfile Trust, and Branch Indexing: Configuration, Design Choices, and Tradeoffs

Choose deliberately between one Pipeline and Multibranch, branch and pull-request discovery traits, polling scans and webhooks, provider fork-trust strategies, trusted libraries and untrusted Jenkinsfile code, and retention policies that balance audit evidence against controller growth.

TradeoffsPR discoveryFork trustWebhooksScan policyShared libraries

Learning objectives

  • Choose Multibranch or a single Pipeline based on repository/job lifecycle requirements.
  • Compare branch and change-request discovery traits and provider trust models.
  • Design scan/webhook policies that avoid unnecessary indexing load and duplicate builds.
  • Separate trusted library/control-plane code from untrusted Jenkinsfile input.
  • Choose bounded orphaned-item retention using audit and controller-storage requirements.

1. One Pipeline job versus Multibranch

Model Strength Cost/risk Good fit
Single Pipeline Simple job identity and permissions Branch selection/trigger logic becomes custom One controlled release branch or explicitly parameterized workflow
Multibranch Automatic child lifecycle and per-head history More items, indexing, trust and retention complexity Repositories where branches/PRs should build independently

Multibranch is not “more modern” by default. Choose it when automatic SCM-head lifecycle is valuable enough to justify the additional discovery and trust surface.

2. Branch versus pull-request discovery

Normal branches are heads in the origin repository. Pull/change requests are provider concepts with additional identities: request number, source/fork repository, candidate revision, target branch and contributor relationship. Provider branch-source plugins expose traits that select which categories to discover and, crucially, how forked contributions are trusted.

Every extra discovery trait increases child-job cardinality. Combine this with Chapter 21: repository count × branches × PR heads × matrix cells can multiply queue demand rapidly.

3. Fork trust is a control-plane decision

A safe provider design answers three questions outside contributor-editable Pipeline code:

  1. Which contributors/PR origins are trusted to supply control files?
  2. Which revision supplies the Jenkinsfile or other trusted configuration?
  3. Which credentials/agents/deployment capabilities are reachable from each trust class?

If the only guard is an if (env.CHANGE_ID) inside the same untrusted Jenkinsfile, a malicious contributor can delete the guard. Treat provider trust policy, job authorization, agent isolation and credential scope as the enforcement layer.

4. Periodic scans versus webhooks/events

A periodic scan is simple and resilient to missed events but consumes SCM/API capacity and introduces detection latency. Webhooks/events reduce latency but require authenticated provider integration and event routing. Many installations use provider events with a low-frequency safety scan.

Trigger Benefit Risk Evidence
Periodic branch index Independent of webhook delivery API load / repeated scans Indexing log and timer cause
Provider webhook/event Low-latency discovery Duplicate/misrouted events if misconfigured Event routing + indexing/build cause
Manual scan Controlled troubleshooting Operator-dependent User/cause + before/after index

5. Trusted libraries versus untrusted Jenkinsfile code

Shared Libraries become Chapter 24’s full topic, but Multibranch trust already depends on them. A library marked trusted can execute privileged APIs that sandboxed/untrusted Pipeline code cannot. Therefore:

  • keep trusted-library repository write access narrow;
  • prefer reviewed, immutable or version-controlled refs for privileged behavior;
  • expose small intent-oriented functions rather than a generic “run arbitrary Groovy” surface;
  • do not let untrusted code select an arbitrary privileged library revision.

6. Orphaned-item retention

Branch churn creates controller state. Immediate deletion reduces disk usage but weakens incident/audit history. Unlimited retention can grow JENKINS_HOME substantially. Choose a bounded strategy using branch lifetime, compliance, rollback needs and backup capacity. Document whether retention is based on days, item count, build count, or a combination supported by the configured strategy.

7. Credential and status-feedback design

SCM discovery usually needs repository metadata/read access; status feedback may need commit-status permissions; protected deployment needs unrelated privileges. Split these identities. A GitHub App or provider integration can be a good production pattern when narrowly scoped, but it remains provider-specific and must not become a broad organization credential merely for convenience.

8. Worked decision: public repository with external contributors

Question Decision Observable evidence
Branch/PR model Multibranch with provider PR source Provider plugin + discovery traits
Fork trust Untrusted by default; approved relationship only if policy allows Trust trait + candidate/trusted revision logs
Untrusted agent Disposable, low privilege, no production network/secret Node/label and infrastructure policy
Deployment Trusted post-merge/release path Separate trusted job/build + protected credential binding
Discovery trigger Provider events + bounded safety scan Event/indexing logs and causes
Retention Bounded orphaned items/builds Configured strategy + storage trend

9. Rollback and reversibility

Changing discovery traits or trust strategy can add/remove many child jobs. Before editing, export/configure-as-code the parent item where available, record the current traits and orphaned policy, and preserve recent indexing logs. Roll back the smallest configuration change rather than deleting/recreating the Multibranch project.

Next lesson

Diagnostics, Failure Modes, Security, and Performance

Diagnose fork-secret exposure, duplicate builds, indexing storms, mutable trusted libraries and stale branch jobs from preserved evidence.

Knowledge check

Answer before revealing the explanation.

1. When is Multibranch better than one manually parameterized Pipeline?

2. Why can scan schedules plus webhooks cause duplicate work?

3. Why are trusted Shared Libraries not automatically safe for untrusted branches?

4. What should drive fork trust policy?

5. Why bound orphaned-item retention?

Official references and version notes

  • Jenkins LTS changelog — chapter baseline Jenkins 2.568.3 LTS, released 2026-09-02 and tested with Java 21 and 25; labs use Java 21.
  • Jenkins: Branches and Pull Requests — Multibranch discovery, branch child jobs, indexing and change-request environment variables.
  • Pipeline: Multibranch — version 841.vec5b_9e1806ec, requiring Jenkins 2.504.3.
  • Branch API — version 2.1280.v0d4e5b_b_460ef; documents Multibranch event/indexing log locations and routing.
  • SCM API — version 728.vc30dcf7a_0df5.
  • Git plugin — version 5.10.1.
  • Git Client plugin — version 6.6.1; current releases include fixes for earlier command-injection issues on agents.
  • GitHub Branch Source — provider-specific optional reference, version 1983.vfa_27ed961853, requiring Jenkins 2.541.1.
  • Pipeline: Multibranch step/reference — documents provider pull-request trust strategies and trusted-file behavior.
  • Credentials API — version 1511.v2e3cb_0008ef0; credentials remain a separate authorization boundary from SCM discovery.

Version note — 2026-09-17: executable local examples assume Jenkins 2.568.3 LTS, Java 21, Pipeline: Multibranch 841.vec5b_9e1806ec, Branch API 2.1280.v0d4e5b_b_460ef, SCM API 728.vc30dcf7a_0df5, Git 5.10.1, and Git Client 6.6.1. GitHub Branch Source 1983.vfa_27ed961853 is used only to explain a real provider fork/PR trust model; the mandatory local lab does not require an external SCM account or real SCM credential. Re-check provider plugin advisories and trust semantics before production adoption.

Keep the academy open

Support free, practical DevOps education.

Every lesson is designed to remain readable in a browser, downloadable from GitHub, and usable without a paid learning platform. Contributions help expand and maintain the curriculum.

Ethereum / ERC-20
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0Send only Ethereum/ERC-20 compatible assets to this address.