Skip to content

Enable multi-branch remote polling #1721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

dbnicholson
Copy link

For as long as we've been using Jenkins, workspaces have been required for polling on jobs with multiple branches. We have a bunch of jobs where the git repo has a code branch and a packaging branch. The job is set to trigger on changes from either branch, and then build merges them together. Since workspace polling automatically triggers a build if there's no workspace, the build script has to be prepared for the case where it's building the same code and should do nothing.

This works fine except that every time we replace our worker nodes, any event on the remote repository triggers the workspace polling and a build to be run. This is multiplied since we often have multiple sets of stable branches from the repositories that have associated Jenkins jobs. It's a lot of pointless busy work when it should be easy to tell that the two fixed branches configured in each job haven't changed.

This PR enables remote pulling for multiple non-wildcard branches. The code was already there to loop over requested branches, but the mode was only triggered for a single non-wildcard branch. I included two other fixes I came across while running the test suite to ensure I was exercising as I expected.

I found several similar issues but not one that was specifically about remote polling being used for multiple branches. I'm happy to update the PR or commit messages if there is one. Here is a search for all git-plugin issues containing ls-remote.

Testing done

Testing has been done with new unit tests and passing of the existing tests. I haven't had a chance to test this on our instance.

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

This essentially reverts 3b7cdff. In 2024, git ls-remote on a local
repo works and the tests already depend on it in
testPolling_CanDoRemotePollingIfOneBranchButMultipleRepositories. Add an
assertion in testBasicRemotePoll to ensure that it's really testing
remote polling.
When a single empty branch is encountered, getSingleBranch converts it
to the ** wildcard spec like BranchSpec. Since that's not null,
requiresWorkspaceForPolling says it can be used with remote polling.
However, remote polling doesn't work well for wildcard branches since it
doesn't have access to the remote history to prune old branches. Detect
this special case and require workspace polling for it.

I'm not sure why getSingleBranch goes to such effort to reject wildcard
branches but then treats allows an empty branch as a wildcard. It seems
like it should return null for an empty branch, but it also gets passed
to getCandidateRevisions, which may expect those semantics.
As long as the branch specs can't match multiple remote branches, then
remote polling can be used since it can (and already does) match each
branch spec against the map returned from `git ls-remote`. Add a
separate helper to determine if all branch specs are simple and use that
to determine if workspace polling is required.
@dbnicholson dbnicholson requested a review from a team as a code owner February 13, 2025 22:05
@github-actions github-actions bot added the tests Automated test addition or improvement label Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Automated test addition or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant