jenkinsci / jenkinsci/github-branch-source-plugin

[JENKINS-44598] git workspace should be reset before build PR merged with base branch

Open
#1,085 17 comments 0 reactions 0 assignees View on GitHub
component:github-branch-source-plugin imported-jira-issue priority:major resolution:unresolved
Dominant language
Java
Stars
217
Forks
398
Avg merge
30m
Merged PRs (30d)
1

Description

The plugin attempts to merge the PR and the base branch before build. However, if git-merge introduces a conflict, the unmerged files will be left in the PR's git workspace, which causes git-merge in the following builds always fail, because the conflict is not solved.

Here's the log snippets:

For build #3, which introduces the merge conflict

> git fetch --tags --progress git@​github.mycompany.com:SERVER_REPO.git +refs/pull//head:refs/remotes/origin/pr/

Merging dev_6_2 commit fc999a1dae8861c1e5d3c21c8deb81f1e7bdf3a8 into PR head commit 5042e295186f8fe4bbb61ac97d97d69d1932912c
> git config core.sparsecheckout # timeout=10
> git checkout -f 5042e295186f8fe4bbb61ac97d97d69d1932912c
> git merge fc999a1dae8861c1e5d3c21c8deb81f1e7bdf3a8 # timeout=10
> git config core.sparsecheckout # timeout=10
> git checkout -f 5042e295186f8fe4bbb61ac97d97d69d1932912c
GitHub has been notified of this commit’s build result
hudson.plugins.git.GitException: Command "git merge fc999a1dae8861c1e5d3c21c8deb81f1e7bdf3a8" returned status code 1:
stdout: Auto-merging docker-environment/ansible/group_vars/all.yml
CONFLICT (add/add): Merge conflict in docker-environment/ansible/group_vars/all.yml
Automatic merge failed; fix conflicts and then commit the result.
stderr:
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1877)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1845)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1841)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1486)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$3.execute(CliGitAPIImpl.java:621)
at org.jenkinsci.plugins.github_branch_source.GitHubSCMSource$MergeWith.decorateRevisionToBuild(GitHubSCMSource.java:1003)
at hudson.plugins.git.GitSCM.determineRevisionToBuild(GitSCM.java:1015)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1108)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:109)
at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:130)
at org.jenkinsci.plugins.workflow.multibranch.SCMBinder.create(SCMBinder.java:107)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:234)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:405)
Finished: FAILURE

For the following build #4, #5 and so on, the merge always fails

> git fetch --tags --progress git@​github.mycompany.com:SERVER_REPO.git +refs/pull//head:refs/remotes/origin/pr/

Merging dev_6_2 commit fc999a1dae8861c1e5d3c21c8deb81f1e7bdf3a8 into PR head commit 32fe21329c3f0349347d029917ba29a39fc0364a
> git config core.sparsecheckout # timeout=10
> git checkout -f 32fe21329c3f0349347d029917ba29a39fc0364a
> git merge fc999a1dae8861c1e5d3c21c8deb81f1e7bdf3a8 # timeout=10
> git config core.sparsecheckout # timeout=10
> git checkout -f 32fe21329c3f0349347d029917ba29a39fc0364a
GitHub has been notified of this commit’s build result
hudson.plugins.git.GitException: Command "git merge fc999a1dae8861c1e5d3c21c8deb81f1e7bdf3a8" returned status code 128:
stdout:
stderr: error: 'merge' is not possible because you have unmerged files.
hint: Fix them up in the work tree,
hint: and then use 'git add/rm ' as
hint: appropriate to mark resolution and make a commit,
hint: or use 'git commit -a'.
fatal: Exiting because of an unresolved conflict.
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1877)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1845)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1841)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1486)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$3.execute(CliGitAPIImpl.java:621)
at org.jenkinsci.plugins.github_branch_source.GitHubSCMSource$MergeWith.decorateRevisionToBuild(GitHubSCMSource.java:1003)
at hudson.plugins.git.GitSCM.determineRevisionToBuild(GitSCM.java:1015)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1108)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:109)
at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:130)
at org.jenkinsci.plugins.workflow.multibranch.SCMBinder.create(SCMBinder.java:107)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:234)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:405)
Finished: FAILURE

 

Then this build will be stuck in this situation unless we manually issue 'git reset HEAD --hard' in that git workspace.

---
Originally reported by asouchang, imported from: git workspace should be reset before build PR merged with base branch


  • status: Open
  • priority: Major
  • component(s): github-branch-source-plugin
  • resolution: Unresolved
  • votes: 9
  • watchers: 16
  • imported: 2025-12-02

Raw content of original issue

The plugin attempts to merge the PR and the base branch before build. However, if git-merge introduces a conflict, the unmerged files will be left in the PR's git workspace, which causes git-merge in the following builds always fail, because the conflict is not solved.

Here's the log snippets:

For build #3, which introduces the merge conflict



> git fetch --tags --progress git@github.mycompany.com:SERVER_REPO.git +refs/pull//head:refs/remotes/origin/pr/

Merging dev_6_2 commit fc999a1dae8861c1e5d3c21c8deb81f1e7bdf3a8 into PR head commit 5042e295186f8fe4bbb61ac97d97d69d1932912c
> git config core.sparsecheckout # timeout=10
> git checkout -f 5042e295186f8fe4bbb61ac97d97d69d1932912c
> git merge fc999a1dae8861c1e5d3c21c8deb81f1e7bdf3a8 # timeout=10
> git config core.sparsecheckout # timeout=10
> git checkout -f 5042e295186f8fe4bbb61ac97d97d69d1932912c
GitHub has been notified of this commit’s build result
hudson.plugins.git.GitException: Command "git merge fc999a1dae8861c1e5d3c21c8deb81f1e7bdf3a8" returned status code 1:
stdout: Auto-merging docker-environment/ansible/group_vars/all.yml
CONFLICT (add/add): Merge conflict in docker-environment/ansible/group_vars/all.yml
Automatic merge failed; fix conflicts and then commit the result.
stderr:
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1877)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1845)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1841)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1486)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$3.execute(CliGitAPIImpl.java:621)
at org.jenkinsci.plugins.github_branch_source.GitHubSCMSource$MergeWith.decorateRevisionToBuild(GitHubSCMSource.java:1003)
at hudson.plugins.git.GitSCM.determineRevisionToBuild(GitSCM.java:1015)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1108)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:109)
at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:130)
at org.jenkinsci.plugins.workflow.multibranch.SCMBinder.create(SCMBinder.java:107)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:234)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:405)
Finished: FAILURE

For the following build #4, #5 and so on, the merge always fails



> git fetch --tags --progress git@github.mycompany.com:SERVER_REPO.git +refs/pull//head:refs/remotes/origin/pr/

Merging dev_6_2 commit fc999a1dae8861c1e5d3c21c8deb81f1e7bdf3a8 into PR head commit 32fe21329c3f0349347d029917ba29a39fc0364a
> git config core.sparsecheckout # timeout=10
> git checkout -f 32fe21329c3f0349347d029917ba29a39fc0364a
> git merge fc999a1dae8861c1e5d3c21c8deb81f1e7bdf3a8 # timeout=10
> git config core.sparsecheckout # timeout=10
> git checkout -f 32fe21329c3f0349347d029917ba29a39fc0364a
GitHub has been notified of this commit’s build result
hudson.plugins.git.GitException: Command "git merge fc999a1dae8861c1e5d3c21c8deb81f1e7bdf3a8" returned status code 128:
stdout:
stderr: error: 'merge' is not possible because you have unmerged files.
hint: Fix them up in the work tree,
hint: and then use 'git add/rm <file>' as
hint: appropriate to mark resolution and make a commit,
hint: or use 'git commit -a'.
fatal: Exiting because of an unresolved conflict.
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1877)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1845)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1841)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1486)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$3.execute(CliGitAPIImpl.java:621)
at org.jenkinsci.plugins.github_branch_source.GitHubSCMSource$MergeWith.decorateRevisionToBuild(GitHubSCMSource.java:1003)
at hudson.plugins.git.GitSCM.determineRevisionToBuild(GitSCM.java:1015)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1108)
at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:109)
at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:130)
at org.jenkinsci.plugins.workflow.multibranch.SCMBinder.create(SCMBinder.java:107)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:234)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:405)
Finished: FAILURE

 

Then this build will be stuck in this situation unless we manually issue 'git reset HEAD --hard' in that git workspace.

environment

```
OS: CentOS 7.3.1611

Jenkins: 2.46.2

GitHub Branch Source Plugin: 2.0.6

git version: 1.8.3.1
```

3 attachments

- [Screen Shot 2017-11-07 at 11.28.43.png](https://issues.jenkins.io/secure/attachment/40242/Screen%20Shot%202017-11-07%20at%2011.28.43.png)
> ![Screen Shot 2017-11-07 at 11.28.43.png](https://issues.jenkins.io/secure/attachment/40242/Screen%20Shot%202017-11-07%20at%2011.28.43.png)
- [image-2023-06-20-09-50-58-110.png](https://issues.jenkins.io/secure/attachment/60815/image-2023-06-20-09-50-58-110.png)
> ![image-2023-06-20-09-50-58-110.png](https://issues.jenkins.io/secure/attachment/60815/image-2023-06-20-09-50-58-110.png)
- [image-2023-07-13-08-40-45-282.png](https://issues.jenkins.io/secure/attachment/60816/image-2023-07-13-08-40-45-282.png)
> ![image-2023-07-13-08-40-45-282.png](https://issues.jenkins.io/secure/attachment/60816/image-2023-07-13-08-40-45-282.png)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.