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

Add an option to add additional remotes to the git repository in SCM

      Sometimes the same repository might have different remotes (for example on different hosting providers) and you might want to work with the branches from different remotes. Other parts of the plugin allow you to specify the remote, but at the moment it can't really be anything other than origin (in the common case), so it seems weird.

      I propose to add an option to add additional remotes to the repo after it's been cloned.
      It could be something as simple as "name: ..., url: ..., (credentials: ...)?".

      One common task that needs this and might be simplified if this is introduced is some automatic mirroring/repo syncing, i.e. when you want to update some branch in one remote with the new commits from some other branch in another remote at some regular intervals (perhaps, performing additional tests each time).

          [JENKINS-55536] Add an option to add additional remotes to the git repository in SCM

          Danila M created issue -

          Mark Waite added a comment -

          Thanks for the report. Can you provide more details to explain why you think the plugin does not support multiple remotes?

          Multiple remotes are supported by Freestyle jobs. Refer to my JENKINS-55536 Freestyle job definition for the confirmation that Freestyle jobs support multiple remotes. Multiple remotes are under the "Advanced" button on the git repository configuration for Freestyle jobs.

          Multiple remotes are supported by Declarative Pipeline and Scripted Pipeline jobs. Refer to the Jenkinsfile in my JENKINS-55536 branch to see the confirmation job that I've added to show multiple remotes in a Pipeline job. Multiple remotes are under the "Advanced" button on the git repository configuration for Pipeline syntax.

          Because use of multiple remotes is an advanced feature, it is not included in the multibranch Pipeline user interface for GitHub branch source, Bitbucket branch source, or Gitea. Each of those branch sources use a more sophisticated web API to detect changes. That web API improves performance dramatically and reduces the load on the Jenkins master and the git hosting server. Even in those cases, multiple remote repositories can be defined and used within the Jenkinsfile hosted in the branches of those repositories (as shown in the Jenkinsfile).

          Mark Waite added a comment - Thanks for the report. Can you provide more details to explain why you think the plugin does not support multiple remotes? Multiple remotes are supported by Freestyle jobs. Refer to my JENKINS-55536 Freestyle job definition for the confirmation that Freestyle jobs support multiple remotes. Multiple remotes are under the "Advanced" button on the git repository configuration for Freestyle jobs. Multiple remotes are supported by Declarative Pipeline and Scripted Pipeline jobs. Refer to the Jenkinsfile in my JENKINS-55536 branch to see the confirmation job that I've added to show multiple remotes in a Pipeline job. Multiple remotes are under the "Advanced" button on the git repository configuration for Pipeline syntax. Because use of multiple remotes is an advanced feature, it is not included in the multibranch Pipeline user interface for GitHub branch source, Bitbucket branch source, or Gitea. Each of those branch sources use a more sophisticated web API to detect changes. That web API improves performance dramatically and reduces the load on the Jenkins master and the git hosting server. Even in those cases, multiple remote repositories can be defined and used within the Jenkinsfile hosted in the branches of those repositories (as shown in the Jenkinsfile ).
          Mark Waite made changes -
          Resolution New: Not A Defect [ 7 ]
          Status Original: Open [ 1 ] New: Fixed but Unreleased [ 10203 ]

          Danila M added a comment - - edited

          There is no option to specify additional remotes in the SCM configuration (for freestyle project).
          There is also absolutely no info/documentation on how to properly set this up in the pipeline. Even knowing what I need to search for thanks to your links I didn't find any conclusive info on how to properly use `userRemoteConfigs` (though I can guess from some examples). Is this the only way?

          Before that, I've tried consulting with several knowledgeable people, but they were also not aware of this feature.

          What do you mean by the ""Advanced" button on the git repository configuration for Pipeline syntax."? There is no such thing. The declarative pipeline configuration is contained withing Jenkinsfile.

          Freestyle project doesn't have advanced options, beside specifying name and refspec.

          There is an option to add additional repositories, however it's not clear what it actually does and I assumed it just clones additional repositories, though now, it seems like it might've been what I was looking for. Then, this option should've been named "add remote" since it adds new remotes to the existing local repository. Of course only if it;s indeed what it does.

          I don't know about multibranch. I've only tried freestyle and regular pipeline projects.

          Danila M added a comment - - edited There is no option to specify additional remotes in the SCM configuration (for freestyle project). There is also absolutely no info/documentation on how to properly set this up in the pipeline. Even knowing what I need to search for thanks to your links I didn't find any conclusive info on how to properly use `userRemoteConfigs` (though I can guess from some examples). Is this the only way? Before that, I've tried consulting with several knowledgeable people, but they were also not aware of this feature. What do you mean by the ""Advanced" button on the git repository configuration for Pipeline syntax."? There is no such thing. The declarative pipeline configuration is contained withing Jenkinsfile. Freestyle project doesn't have advanced options, beside specifying name and refspec. There is an option to add additional repositories, however it's not clear what it actually does and I assumed it just clones additional repositories, though now, it seems like it might've been what I was looking for. Then, this option should've been named "add remote" since it adds new remotes to the existing local repository. Of course only if it;s indeed what it does. I don't know about multibranch. I've only tried freestyle and regular pipeline projects.
          Mark Waite made changes -
          Attachment New: pipeline-syntax-access.png [ 45636 ]
          Mark Waite made changes -
          Attachment New: screenshot-1.png [ 45637 ]
          Mark Waite made changes -
          Attachment Original: screenshot-1.png [ 45637 ]
          Mark Waite made changes -
          Attachment New: pipeline-syntax-checkout.png [ 45638 ]

          Mark Waite added a comment - - edited

          You're correct that the "add additional repositories" option is a source of confusion. Other users assumed it was some way to include multiple independent repositories in a single workspace. Rather, it handles only the case that you're describing, additional additional remotes as sources for the same repository.

          The Pipeline Syntax hint for the checkout step presents a similar user interface as is available with Freestyle jobs. It is quite a helpful utility to construct Pipeline syntax. It is available as:

          Multiple remotes for a single job is not a widely used or well-known feature because it has significant limitations on its use. I don't especially want to document its use because it is such an advanced feature. You're welcome to use it. There are several automated tests which confirm that it is still working, but it is a narrow enough use that I'd rather not publicize it widely.

          If you feel strongly that it should be documented, you're welcome to submit documentation to the git plugin wiki page or to submit a pull request to jenkins.io with documentation.

          Mark Waite added a comment - - edited You're correct that the "add additional repositories" option is a source of confusion. Other users assumed it was some way to include multiple independent repositories in a single workspace. Rather, it handles only the case that you're describing, additional additional remotes as sources for the same repository. The Pipeline Syntax hint for the checkout step presents a similar user interface as is available with Freestyle jobs. It is quite a helpful utility to construct Pipeline syntax. It is available as: Multiple remotes for a single job is not a widely used or well-known feature because it has significant limitations on its use. I don't especially want to document its use because it is such an advanced feature. You're welcome to use it. There are several automated tests which confirm that it is still working, but it is a narrow enough use that I'd rather not publicize it widely. If you feel strongly that it should be documented, you're welcome to submit documentation to the git plugin wiki page or to submit a pull request to jenkins.io with documentation.
          Mark Waite made changes -
          Status Original: Fixed but Unreleased [ 10203 ] New: Closed [ 6 ]

            markewaite Mark Waite
            danilaml Danila M
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: