Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-44598

git workspace should be reset before build PR merged with base branch

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • OS: CentOS 7.3.1611
      Jenkins: 2.46.2
      GitHub Branch Source Plugin: 2.0.6
      git version: 1.8.3.1

      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.

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

          Asou Chang created issue -
          Asou Chang made changes -
          Description Original: 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.
          New: 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
          {code:java}
          > 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
          {code}

           For the following build #4, #5 and so on, the merge always fails
          {code:java}
          > 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
          {code}

            

          Then this build will be stuck in this situation unless we manually issue 'git reset HEAD --hard' in that git workspace.
          Volodymyr Nekhai made changes -
          Priority Original: Minor [ 4 ] New: Major [ 3 ]
          Stephen Connolly made changes -
          Link New: This issue is blocked by JENKINS-45771 [ JENKINS-45771 ]
          Stephen Connolly made changes -
          Issue Type Original: Improvement [ 4 ] New: Bug [ 1 ]
          Stephen Connolly made changes -
          Link New: This issue is related to JENKINS-47737 [ JENKINS-47737 ]
          Stephen Connolly made changes -
          Attachment New: Screen Shot 2017-11-07 at 11.28.43.png [ 40242 ]
          Krzysztof made changes -
          Attachment New: image-2023-06-20-09-50-58-110.png [ 60814 ]
          Krzysztof made changes -
          Attachment Original: image-2023-06-20-09-50-58-110.png [ 60814 ]
          Krzysztof made changes -
          Attachment New: image-2023-06-20-09-50-58-110.png [ 60815 ]
          Krzysztof made changes -
          Attachment New: image-2023-07-13-08-40-45-282.png [ 60816 ]

            Unassigned Unassigned
            asouchang Asou Chang
            Votes:
            9 Vote for this issue
            Watchers:
            16 Start watching this issue

              Created:
              Updated: