@@ -95,6 +95,85 @@ def configtree_with_default_branch(self):
9595 '''
9696 return config_node
9797
98+ def configtree_multibranch_git (self ):
99+ config_node = '''
100+ <flow-definition plugin="[email protected] "> 101+ <keepDependencies>false</keepDependencies>
102+ <properties>
103+ <org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
104+ <triggers>
105+ <hudson.triggers.TimerTrigger>
106+ <spec>H H * * H(6-7)</spec>
107+ </hudson.triggers.TimerTrigger>
108+ <jenkins.triggers.ReverseBuildTrigger>
109+ <spec></spec>
110+ <upstreamProjects></upstreamProjects>
111+ <threshold>
112+ <name>SUCCESS</name>
113+ <ordinal>0</ordinal>
114+ <color>BLUE</color>
115+ <completeBuild>true</completeBuild>
116+ </threshold>
117+ </jenkins.triggers.ReverseBuildTrigger>
118+ </triggers>
119+ </org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
120+ <jenkins.model.BuildDiscarderProperty>
121+ <strategy class="hudson.tasks.LogRotator">
122+ <daysToKeep>-1</daysToKeep>
123+ <numToKeep>5</numToKeep>
124+ <artifactDaysToKeep>-1</artifactDaysToKeep>
125+ <artifactNumToKeep>5</artifactNumToKeep>
126+ </strategy>
127+ </jenkins.model.BuildDiscarderProperty>
128+ <org.jenkinsci.plugins.workflow.multibranch.BranchJobProperty
129+ 130+ <branch plugin="[email protected] "> 131+ <sourceId>a2d4bcda-6141-4af2-8088-39139a147902</sourceId>
132+ <head class="com.cloudbees.jenkins.plugins.bitbucket.BranchSCMHead"
133+ 134+ <name>master</name>
135+ <repositoryType>GIT</repositoryType>
136+ </head>
137+ <scm class="hudson.plugins.git.GitSCM" plugin="[email protected] "> 138+ <configVersion>2</configVersion>
139+ <userRemoteConfigs>
140+ <hudson.plugins.git.UserRemoteConfig>
141+ <name>origin</name>
142+ <refspec>+refs/heads/master:refs/remotes/origin/master</refspec>
143+ <url>ssh://[email protected] /project-name/reponame.git</url> 144+ <credentialsId>jenkins-stash</credentialsId>
145+ </hudson.plugins.git.UserRemoteConfig>
146+ </userRemoteConfigs>
147+ <branches class="singleton-list">
148+ <hudson.plugins.git.BranchSpec>
149+ <name>master</name>
150+ </hudson.plugins.git.BranchSpec>
151+ </branches>
152+ <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
153+ <browser class="hudson.plugins.git.browser.BitbucketWeb">
154+ <url>https://bitbucket.site/projects/project-name/repos/reponame</url>
155+ </browser>
156+ <submoduleCfg class="empty-list"/>
157+ <extensions>
158+ <jenkins.plugins.git.GitSCMSourceDefaults>
159+ <includeTags>false</includeTags>
160+ </jenkins.plugins.git.GitSCMSourceDefaults>
161+ </extensions>
162+ </scm>
163+ <properties/>
164+ </branch>
165+ </org.jenkinsci.plugins.workflow.multibranch.BranchJobProperty>
166+ </properties>
167+ <definition class="org.jenkinsci.plugins.workflow.multibranch.SCMBinder"
168+ 169+ <scriptPath>Jenkinsfile</scriptPath>
170+ </definition>
171+ <triggers/>
172+ <disabled>false</disabled>
173+ </flow-definition>
174+ '''
175+ return config_node
176+
98177 @mock .patch .object (Job , 'get_config' , configtree_with_branch )
99178 def test_hg_attributes (self ):
100179 expected_url = ['http://cm5/hg/sandbox/v01.0/int' ]
@@ -106,6 +185,13 @@ def test_hg_attributes(self):
106185 def test_hg_attributes_default_branch (self ):
107186 self .assertEqual (self .j .get_scm_branch (), ['default' ])
108187
188+ @mock .patch .object (Job , 'get_config' , configtree_multibranch_git )
189+ def test_git_attributes_multibranch (self ):
190+ expected_url = [
'ssh://[email protected] /project-name/reponame.git' ]
191+ self .assertEqual (self .j .get_scm_type (), 'git' )
192+ self .assertEqual (self .j .get_scm_url (), expected_url )
193+ self .assertEqual (self .j .get_scm_branch (), ['master' ])
194+
109195
110196if __name__ == '__main__' :
111197 unittest .main ()
0 commit comments