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

Git Plugin fails to mergeBeforeBuild with "ambiguous argument"

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      Hello, we have a Blue Ocean pipeline that is failing on the checkout step and we can't seem to figure out what the issue is. 

      Our checkout step looks like

      checkout([                    
        $class: 'GitSCM',                    
        branches: scm.branches,                    
        extensions: scm.extensions + [[$class: 'WipeWorkspace'], [$class: 'LocalBranch'], [$class: 'PreBuildMerge', options: [mergeStrategy: 'RESOLVE', mergeRemote: 'origin', mergeTarget: 'master']]],                    
        userRemoteConfigs: scm.userRemoteConfigs                
      ])
      

       

      The error that is happening in the pipeline is

      using credential github
      Wiping out workspace first.
      Cloning the remote Git repository
      Cloning with configured refspecs honoured and without tags
      Cloning repository https://github.com/sample/myrepo.git
       > git init /usr/local/jenkins/workspace/repo_update_pipeline # timeout=10
      Fetching upstream changes from https://github.com/sample/myrepo.git
       > git --version # timeout=10
      using GIT_ASKPASS to set credentials GitHub Access Token
       > git fetch --no-tags --progress https://github.com/sample/myrepo.git +refs/heads/update_pipeline:refs/remotes/origin/update_pipeline # timeout=10
      Cleaning workspace
      Fetching without tags
       > git config remote.origin.url https://github.com/sample/myrepo.git # timeout=10
       > git config --add remote.origin.fetch +refs/heads/update_pipeline:refs/remotes/origin/update_pipeline # timeout=10
       > git config remote.origin.url https://github.com/sample/myrepo.git # timeout=10
       > git rev-parse --verify HEAD # timeout=10
      No valid HEAD. Skipping the resetting
       > git clean -fdx # timeout=10
      Fetching upstream changes from https://github.com/sample/myrepo.git
      using GIT_ASKPASS to set credentials GitHub Access Token
       > git fetch --no-tags --progress https://github.com/sample/myrepo.git +refs/heads/update_pipeline:refs/remotes/origin/update_pipeline # timeout=10
      Merging Revision 842081ddebb2be48b43005b7dccf5e26a1cbb04a (update_pipeline) to origin/master, UserMergeOptions{mergeRemote='origin', mergeTarget='master', mergeStrategy='RESOLVE', fastForwardMode='FF'}
      Command "git rev-parse origin/master^{commit}" returned status code 128:
      stdout: origin/master^{commit}
      
      stderr: fatal: ambiguous argument 'origin/master^{commit}': unknown revision or path not in the working tree.
      Use '--' to separate paths from revisions, like this:'git <command> [<revision>...] -- [<file>...]'

      I believe the issue is that the pipeline is not fetching the master branch when performing the initial clone or any following step, but I've tried a number of config settings to try to entice it to pull master for merging.

      Am I missing something or is there a bug in this behavior? Based on the Snippet Generator, this not what I would expect the behavior to be based on the available options.

      For what it's worth, I am attempting to get the PreBuildMerge plugin working properly, we want to stage merging our branch into master and run the pipeline on the merged code which seems to work whenever master happens to exist in the branch workspace but not when it's a clean clone.

        Attachments

          Activity

          Hide
          markewaite Mark Waite added a comment -

          Merge is best done through the branch source plugins (GitHub, Bitbucket, and Gitea) rather than through the git plugin. The branch source plugins provide options to evaluate pull requests and they provide the necessary configuration to support the evaluation of pull requests.

          If your environment won't allow you to use one of those branch source plugins, then the refspec used in the checkout needs to be extended to include the branch that is being merged in addition to the branch that is being built. Your example log lists:

           > git fetch --no-tags --progress https://github.com/sample/myrepo.git +refs/heads/update_pipeline:refs/remotes/origin/update_pipeline # timeout=10
          

          That statement uses a narrow refspec that pulls only the branch being built ( update_pipeline ) and no other branches. That reduces the impact of the CI job on the remote server by requesting only the data needed for that specific branch. It also means that other branches are not available in the workspace repository.

          You'll need to either use the GitHub branch source plugin (preferred) or adjust the remote config that is currently listed as:

          userRemoteConfigs: scm.userRemoteConfigs

          Show
          markewaite Mark Waite added a comment - Merge is best done through the branch source plugins (GitHub, Bitbucket, and Gitea) rather than through the git plugin. The branch source plugins provide options to evaluate pull requests and they provide the necessary configuration to support the evaluation of pull requests. If your environment won't allow you to use one of those branch source plugins, then the refspec used in the checkout needs to be extended to include the branch that is being merged in addition to the branch that is being built. Your example log lists: > git fetch --no-tags --progress https://github.com/sample/myrepo.git +refs/heads/update_pipeline:refs/remotes/origin/update_pipeline # timeout=10 That statement uses a narrow refspec that pulls only the branch being built ( update_pipeline ) and no other branches. That reduces the impact of the CI job on the remote server by requesting only the data needed for that specific branch. It also means that other branches are not available in the workspace repository. You'll need to either use the GitHub branch source plugin (preferred) or adjust the remote config that is currently listed as: userRemoteConfigs: scm.userRemoteConfigs

            People

            • Assignee:
              Unassigned
              Reporter:
              cardonator Ben Cardon
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: