Change default PR build strategy from merge to head #636
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When multibranch was first written, using PR merge build strategy seemed like a neat way to ensure that trunk was never broken. But this strategy comes with downsides:
gh pr checkout 123 && make
can produce different results than CI.github-checks
submit a commit status or check but then need to account for the fact that the built commit might be an ephemeral merge commit and the submission actually needs to use the first parent—though it might not, even in merge strategy, if the PR head is already up to date.In practice, it is not very common that two pull requests are filed which individually pass CI, fail CI in combination, and yet have no textual merge conflicts (edits within ~3 lines of one another). It can certainly happen (jenkinsci/script-security-plugin#468 is an example) but not very often, and it is even less common that the failure is so weird that is difficult to fix trunk retroactively.
Furthermore, since this feature was conceived, GitHub itself has evolved to include branch protections such as the rule that a PR must be up to date before merging (which Dependabot will automatically honor by rebasing); as well as the introduction of a merge queue feature that supersedes this Jenkins trick.
This patch simply changes the default for multibranch projects or organization folders newly created via the GUI, to the simpler and more comprehensible head mode: build whatever was last pushed to the PR branch. Example result in
config.xml
:For what I suppose are historical reasons,
strategyId
is anint
rather than a more legibleenum
:github-branch-source-plugin/src/main/java/org/jenkinsci/plugins/github_branch_source/OriginPullRequestDiscoveryTrait.java
Lines 57 to 67 in 3a76035