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

Specify a remote name different from the repository slug

      Hello,

      I was wondering how to manage the refspec for a repository cloned using the Bitbucket Server plugin? We would like to clone into origin instead of the branch name.

      Thank you!

          [JENKINS-67890] Specify a remote name different from the repository slug

          Katie Black created issue -

          Martin Henschke added a comment - - edited

          Hi Katie, thanks for the report.

          I'm afraid I don't 100% understand your question. When you say you want to "clone into origin instead of the branch name", are you saying you wish the branch name to be named 'origin', or are you trying to perform a clone operation in Bitbucket?

          If you could please share some exact steps of what you're trying to do, that'd be really helpful. Thank you!

          Martin Henschke added a comment - - edited Hi Katie, thanks for the report. I'm afraid I don't 100% understand your question. When you say you want to "clone into origin instead of the branch name", are you saying you wish the branch name to be named 'origin', or are you trying to perform a clone operation in Bitbucket? If you could please share some exact steps of what you're trying to do, that'd be really helpful. Thank you!
          Atlassian Bitbucket Server made changes -
          Assignee New: Katie Black [ keblack789 ]
          Atlassian Bitbucket Server made changes -
          Issue Type Original: Bug [ 1 ] New: Improvement [ 4 ]

          Josh Mueller added a comment -

          I also experienced what appears to be this or a very similar issue. The Git SCM plugin defaults the remote name to "origin" when the refspec is not provided in the job config. The Bitbucket Server Integration SCM plugin, by comparison, uses the repo name as the remote and does not appear to provide a way to override this.

          When I started switching jobs to use the Bitbucket Server Integration plugin I had to rework several scripts that performed git operations and assumed the remote was origin. The ability to set the refspec would have avoided these changes.

          A slightly obfuscated example from the job build console log before and after converting a job:

          Git SCM

          > git fetch --tags --progress --prune --depth=10 -- ssh://git@<bitbucket>:7999/<project>/<repo>.git +refs/heads/*:refs/remotes/origin/* # timeout=10

          Bitbucket Server Integration

          > git fetch --tags --progress --prune --depth=10 -- ssh://git@<bitbucket>:7999/<project>/<repo>.git +refs/heads/*:refs/remotes/<repo>/* # timeout=10

           

          Josh Mueller added a comment - I also experienced what appears to be this or a very similar issue. The Git SCM plugin defaults the remote name to "origin" when the refspec is not provided in the job config. The Bitbucket Server Integration SCM plugin, by comparison, uses the repo name as the remote and does not appear to provide a way to override this. When I started switching jobs to use the Bitbucket Server Integration plugin I had to rework several scripts that performed git operations and assumed the remote was origin. The ability to set the refspec would have avoided these changes. A slightly obfuscated example from the job build console log before and after converting a job: Git SCM > git fetch --tags --progress --prune --depth=10 -- ssh://git@<bitbucket>:7999/<project>/<repo>.git +refs/heads/*:refs/remotes/origin/* # timeout=10 Bitbucket Server Integration > git fetch --tags --progress --prune --depth=10 -- ssh://git@<bitbucket>:7999/<project>/<repo>.git +refs/heads/*:refs/remotes/<repo>/* # timeout=10  

          I cannot reproduce this with a multibranch pipeline project on Jenkins 2.332.1, Git client plugin 3.11.0, Git plugin 4.11.0, and Bitbucket Server Integration 3.2.0. The remote name is "origin" unless I add the "Configure remote name" behaviour (I think that's RemoteNameSCMSourceTrait).

          Are you using a different type of project?

          Kalle Niemitalo added a comment - I cannot reproduce this with a multibranch pipeline project on Jenkins 2.332.1, Git client plugin 3.11.0, Git plugin 4.11.0, and Bitbucket Server Integration 3.2.0. The remote name is "origin" unless I add the "Configure remote name" behaviour (I think that's RemoteNameSCMSourceTrait ). Are you using a different type of project?

          Josh Mueller added a comment -

          The versions I am working with are:

          • Jenkins 2.303.3
          • Bitbucket Server Integration 3.2.0
          • Git plugin 4.10.3
          • git version 2.14.4

          I see this behavior in both freestyle projects and pipeline projects.

          A quick sample of the jenkinsfile for the pipeline job that has the issue:

          pipeline {
              agent any
              stages {
                  stage( 'Jenkins setup' ) {
                      steps {
                          script {
                              checkout BbS(
                                  branches: [[name: "<repo>/master"]],
                                  credentialsId: '<credentials>',
                                  extensions: [
                                      [$class: 'CloneOption', depth: 10, noTags: false, reference: '', shallow: true],
                                      [$class: 'RelativeTargetDirectory', relativeTargetDir: '<dir>'],
                                      [$class: 'CleanBeforeCheckout'],
                                      [$class: 'PruneStaleBranch']
                                  ],
                                  id: '<id>',
                                  mirrorName: '',
                                  projectName: '<project>',
                                  repositoryName: '<repo>',
                                  serverId: '<server id>',
                                  sshCredentialsId: '<credentials>'
                              )
                          }
                      }
                  }
              }
          }
          

          Josh Mueller added a comment - The versions I am working with are: Jenkins 2.303.3 Bitbucket Server Integration 3.2.0 Git plugin 4.10.3 git version 2.14.4 I see this behavior in both freestyle projects and pipeline projects. A quick sample of the jenkinsfile for the pipeline job that has the issue: pipeline { agent any stages { stage( 'Jenkins setup' ) { steps { script { checkout BbS( branches: [[name: "<repo>/master" ]], credentialsId: '<credentials>' , extensions: [ [$class: 'CloneOption' , depth: 10, noTags: false , reference: '', shallow: true ], [$class: 'RelativeTargetDirectory' , relativeTargetDir: '<dir>' ], [$class: 'CleanBeforeCheckout' ], [$class: 'PruneStaleBranch' ] ], id: '<id>' , mirrorName: '', projectName: '<project>' , repositoryName: '<repo>' , serverId: '<server id>' , sshCredentialsId: '<credentials>' ) } } } } }

          I see. Perhaps it comes from BitbucketSCM.initializeGitScm, which passes getRepositorySlug() as String name to the UserRemoteConfig constructor.

          BitbucketSCMSource.initializeGitScmSource does the same, but that does not seem to affect the clone on the agent. Does it affect something on the controller, instead?

          In the Bitbucket Branch Source plugin, BitbucketGitSCMBuilder doesn't seem to configure the remote name, except when building a pull request merge. I suppose GitSCMBuilder.remoteName then retains its default value.

          Kalle Niemitalo added a comment - I see. Perhaps it comes from BitbucketSCM.initializeGitScm , which passes getRepositorySlug() as String name to the UserRemoteConfig constructor . BitbucketSCMSource.initializeGitScmSource does the same, but that does not seem to affect the clone on the agent. Does it affect something on the controller, instead? In the Bitbucket Branch Source plugin, BitbucketGitSCMBuilder doesn't seem to configure the remote name, except when building a pull request merge. I suppose GitSCMBuilder.remoteName then retains its default value.
          Kalle Niemitalo made changes -
          Summary Original: Specify RefSpec New: Specify a remote name different from the repository slug

          I retitled this issue to match what minielim described. I hope this is also what keblack789 meant.

          Kalle Niemitalo added a comment - I retitled this issue to match what minielim described. I hope this is also what keblack789 meant.

            keblack789 Katie Black
            keblack789 Katie Black
            Votes:
            3 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated: