forked from ramonvanalteren/jenkinsapi-old
-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
job.py: manage scm data for multibranch pipelines (#742)
- Loading branch information
1 parent
dce4073
commit 8e93675
Showing
2 changed files
with
99 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,6 +95,85 @@ def configtree_with_default_branch(self): | |
''' | ||
return config_node | ||
|
||
def configtree_multibranch_git(self): | ||
config_node = ''' | ||
<flow-definition plugin="[email protected]"> | ||
<keepDependencies>false</keepDependencies> | ||
<properties> | ||
<org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty> | ||
<triggers> | ||
<hudson.triggers.TimerTrigger> | ||
<spec>H H * * H(6-7)</spec> | ||
</hudson.triggers.TimerTrigger> | ||
<jenkins.triggers.ReverseBuildTrigger> | ||
<spec></spec> | ||
<upstreamProjects></upstreamProjects> | ||
<threshold> | ||
<name>SUCCESS</name> | ||
<ordinal>0</ordinal> | ||
<color>BLUE</color> | ||
<completeBuild>true</completeBuild> | ||
</threshold> | ||
</jenkins.triggers.ReverseBuildTrigger> | ||
</triggers> | ||
</org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty> | ||
<jenkins.model.BuildDiscarderProperty> | ||
<strategy class="hudson.tasks.LogRotator"> | ||
<daysToKeep>-1</daysToKeep> | ||
<numToKeep>5</numToKeep> | ||
<artifactDaysToKeep>-1</artifactDaysToKeep> | ||
<artifactNumToKeep>5</artifactNumToKeep> | ||
</strategy> | ||
</jenkins.model.BuildDiscarderProperty> | ||
<org.jenkinsci.plugins.workflow.multibranch.BranchJobProperty | ||
plugin="[email protected]"> | ||
<branch plugin="[email protected]"> | ||
<sourceId>a2d4bcda-6141-4af2-8088-39139a147902</sourceId> | ||
<head class="com.cloudbees.jenkins.plugins.bitbucket.BranchSCMHead" | ||
plugin="[email protected]"> | ||
<name>master</name> | ||
<repositoryType>GIT</repositoryType> | ||
</head> | ||
<scm class="hudson.plugins.git.GitSCM" plugin="[email protected]"> | ||
<configVersion>2</configVersion> | ||
<userRemoteConfigs> | ||
<hudson.plugins.git.UserRemoteConfig> | ||
<name>origin</name> | ||
<refspec>+refs/heads/master:refs/remotes/origin/master</refspec> | ||
<url>ssh://[email protected]/project-name/reponame.git</url> | ||
<credentialsId>jenkins-stash</credentialsId> | ||
</hudson.plugins.git.UserRemoteConfig> | ||
</userRemoteConfigs> | ||
<branches class="singleton-list"> | ||
<hudson.plugins.git.BranchSpec> | ||
<name>master</name> | ||
</hudson.plugins.git.BranchSpec> | ||
</branches> | ||
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations> | ||
<browser class="hudson.plugins.git.browser.BitbucketWeb"> | ||
<url>https://bitbucket.site/projects/project-name/repos/reponame</url> | ||
</browser> | ||
<submoduleCfg class="empty-list"/> | ||
<extensions> | ||
<jenkins.plugins.git.GitSCMSourceDefaults> | ||
<includeTags>false</includeTags> | ||
</jenkins.plugins.git.GitSCMSourceDefaults> | ||
</extensions> | ||
</scm> | ||
<properties/> | ||
</branch> | ||
</org.jenkinsci.plugins.workflow.multibranch.BranchJobProperty> | ||
</properties> | ||
<definition class="org.jenkinsci.plugins.workflow.multibranch.SCMBinder" | ||
plugin="[email protected]"> | ||
<scriptPath>Jenkinsfile</scriptPath> | ||
</definition> | ||
<triggers/> | ||
<disabled>false</disabled> | ||
</flow-definition> | ||
''' | ||
return config_node | ||
|
||
@mock.patch.object(Job, 'get_config', configtree_with_branch) | ||
def test_hg_attributes(self): | ||
expected_url = ['http://cm5/hg/sandbox/v01.0/int'] | ||
|
@@ -106,6 +185,13 @@ def test_hg_attributes(self): | |
def test_hg_attributes_default_branch(self): | ||
self.assertEqual(self.j.get_scm_branch(), ['default']) | ||
|
||
@mock.patch.object(Job, 'get_config', configtree_multibranch_git) | ||
def test_git_attributes_multibranch(self): | ||
expected_url = ['ssh://[email protected]/project-name/reponame.git'] | ||
self.assertEqual(self.j.get_scm_type(), 'git') | ||
self.assertEqual(self.j.get_scm_url(), expected_url) | ||
self.assertEqual(self.j.get_scm_branch(), ['master']) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |