[JENKINS-57587] Prevent GitSCMFileSystem NPE on '*' branch name #914
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.
JENKINS-57587 - Prevent GitSCMFileSystem NPE on '*' branch
When a Pipeline job that is not a multibranch Pipeline job is defined to use '
*
' as its branch name and is configured with lightweight checkout, it reports a null pointer exception and fails the job. A branch name '*
' should be disallowed for Pipeline jobs that are not multibranch Pipeline jobs because a wildcard branch name would cause the job to switch between different branches each time it detects a change on one of the branches in the repository. Switching branches within a job makes the change history and general user experience confusing for the user.This has the questionable result that by avoiding the null pointer exception it now allows a Pipeline job that is not a multibranch Pipeline to switch from one branch to another inside the same job.
The technique of using a single job to validate multiple branches was commonly used with Freestyle jobs because they did not have the concept of multibranch. It is generally much better to allow Jenkins to manage the Pipeline jobs with multibranch rather than having a single job that switches between branches. However, a null pointer exception is not a friendly way to tell users that they should not use a specific technique.
Special thanks to Sven Hickstein for his suggestion to use the
supports
method to detect this case. It is a much simpler change thanks to his suggestion.Checklist
Types of changes