Merge "SCM module: Add support for multiple Git remotes."
This commit is contained in:
commit
36cffd95ce
@ -44,6 +44,13 @@ def git(self, xml_parent, data):
|
||||
:arg str credentials-id: ID of credentials to use to connect (optional)
|
||||
:arg str refspec: refspec to fetch
|
||||
:arg str name: name to fetch
|
||||
:arg list(str) remotes: list of remotes to set up (optional, only needed if
|
||||
multiple remotes need to be set up)
|
||||
|
||||
:Remote: * **url** (`string`) - url of remote repo
|
||||
* **refspec** (`string`) - refspec to fetch (optional)
|
||||
* **credentials-id** - ID of credentials to use to connect
|
||||
(optional)
|
||||
:arg list(str) branches: list of branch specifiers to build
|
||||
:arg list(str) excluded-users: list of users to ignore revisions from
|
||||
when polling for changes. (if polling is enabled)
|
||||
@ -136,16 +143,27 @@ def git(self, xml_parent, data):
|
||||
'scm', {'class': 'hudson.plugins.git.GitSCM'})
|
||||
XML.SubElement(scm, 'configVersion').text = '2'
|
||||
user = XML.SubElement(scm, 'userRemoteConfigs')
|
||||
huser = XML.SubElement(user, 'hudson.plugins.git.UserRemoteConfig')
|
||||
XML.SubElement(huser, 'name').text = data.get('name', 'origin')
|
||||
if 'refspec' in data:
|
||||
refspec = data['refspec']
|
||||
else:
|
||||
refspec = '+refs/heads/*:refs/remotes/origin/*'
|
||||
XML.SubElement(huser, 'refspec').text = refspec
|
||||
XML.SubElement(huser, 'url').text = data['url']
|
||||
if 'credentials-id' in data:
|
||||
XML.SubElement(huser, 'credentialsId').text = data['credentials-id']
|
||||
if 'remotes' not in data:
|
||||
data['remotes'] = [{data.get('name', 'origin'): data}]
|
||||
for remoteData in data['remotes']:
|
||||
huser = XML.SubElement(user, 'hudson.plugins.git.UserRemoteConfig')
|
||||
remoteName = remoteData.keys()[0]
|
||||
XML.SubElement(huser, 'name').text = remoteName
|
||||
remoteParams = remoteData.values()[0]
|
||||
if 'refspec' in remoteParams:
|
||||
refspec = remoteParams['refspec']
|
||||
else:
|
||||
refspec = '+refs/heads/*:refs/remotes/' + remoteName + '/*'
|
||||
XML.SubElement(huser, 'refspec').text = refspec
|
||||
if 'url' in remoteParams:
|
||||
remoteURL = remoteParams['url']
|
||||
else:
|
||||
raise JenkinsJobsException('Must specify a url for git remote \"' +
|
||||
remoteName + '"')
|
||||
XML.SubElement(huser, 'url').text = remoteURL
|
||||
if 'credentials-id' in remoteParams:
|
||||
credentialsId = remoteParams['credentials-id']
|
||||
XML.SubElement(huser, 'credentialsId').text = credentialsId
|
||||
xml_branches = XML.SubElement(scm, 'branches')
|
||||
branches = data.get('branches', ['**'])
|
||||
for branch in branches:
|
||||
|
43
tests/scm/fixtures/git-multiple-remotes.xml
Normal file
43
tests/scm/fixtures/git-multiple-remotes.xml
Normal file
@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<scm class="hudson.plugins.git.GitSCM">
|
||||
<configVersion>2</configVersion>
|
||||
<userRemoteConfigs>
|
||||
<hudson.plugins.git.UserRemoteConfig>
|
||||
<name>internal</name>
|
||||
<refspec>+refs/heads/*:refs/remotes/internal/*</refspec>
|
||||
<url>ssh://git@internal.example.com/foobar.git</url>
|
||||
<credentialsId>01234567-89ab-cdef-0123-456789abcdef</credentialsId>
|
||||
</hudson.plugins.git.UserRemoteConfig>
|
||||
<hudson.plugins.git.UserRemoteConfig>
|
||||
<name>github</name>
|
||||
<refspec>+refs/heads/*:refs/remotes/github/*</refspec>
|
||||
<url>https://github.com/exampleuser/foobar.git</url>
|
||||
</hudson.plugins.git.UserRemoteConfig>
|
||||
</userRemoteConfigs>
|
||||
<branches>
|
||||
<hudson.plugins.git.BranchSpec>
|
||||
<name>github/master</name>
|
||||
</hudson.plugins.git.BranchSpec>
|
||||
</branches>
|
||||
<excludedUsers/>
|
||||
<buildChooser class="hudson.plugins.git.util.DefaultBuildChooser"/>
|
||||
<disableSubmodules>false</disableSubmodules>
|
||||
<recursiveSubmodules>false</recursiveSubmodules>
|
||||
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
|
||||
<authorOrCommitter>false</authorOrCommitter>
|
||||
<clean>false</clean>
|
||||
<wipeOutWorkspace>true</wipeOutWorkspace>
|
||||
<pruneBranches>false</pruneBranches>
|
||||
<remotePoll>false</remotePoll>
|
||||
<gitTool>Default</gitTool>
|
||||
<submoduleCfg class="list"/>
|
||||
<relativeTargetDir/>
|
||||
<reference/>
|
||||
<gitConfigName/>
|
||||
<gitConfigEmail/>
|
||||
<skipTag>false</skipTag>
|
||||
<scmName/>
|
||||
<useShallowClone>false</useShallowClone>
|
||||
</scm>
|
||||
</project>
|
10
tests/scm/fixtures/git-multiple-remotes.yaml
Normal file
10
tests/scm/fixtures/git-multiple-remotes.yaml
Normal file
@ -0,0 +1,10 @@
|
||||
scm:
|
||||
- git:
|
||||
remotes:
|
||||
- internal:
|
||||
url: ssh://git@internal.example.com/foobar.git
|
||||
credentials-id: 01234567-89ab-cdef-0123-456789abcdef
|
||||
- github:
|
||||
url: https://github.com/exampleuser/foobar.git
|
||||
branches:
|
||||
- github/master
|
Loading…
Reference in New Issue
Block a user