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.

All CI/CD questions

More on Jenkins