How does Jenkins decide which Jenkinsfile and agent to use in a multibranch job?
AdvancedConceptJenkins
Answer
Branch Sources (GitHub, GitLab, Git) discover branches, PRs and tags. For each one, Jenkins checks out a lightweight view of the repo, looks for the path set in "Script Path" (default Jenkinsfile), and creates a child job if found. The Jenkinsfile loaded is the one from that branch/PR head. For PRs from forks, trust strategies decide whose Jenkinsfile is used: "Trust contributors" runs the PR's version, while "Trust nobody" uses the target branch's, preventing a fork from modifying the pipeline to steal credentials.
Scanning happens on a schedule or webhook, and "Orphaned item strategy" controls how long stale branch jobs are kept.
More on Jenkins
What is Jenkins and how is its architecture organised?BeginnerWhat are executors, nodes and labels in Jenkins?IntermediateWhy should you not run builds on the Jenkins controller?BeginnerHow do inbound (JNLP/WebSocket) and SSH agents connect to the controller?IntermediateWhat is a Jenkinsfile and where does it live?BeginnerDeclarative versus Scripted Pipeline: what are the differences?Intermediate