summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoost van der Griendt <j.vandergriendt@flusso.nl>2016-11-28 14:35:55 -0800
committerSorin Sbarnea <ssbarnea@redhat.com>2018-03-15 16:51:32 +0000
commitefc5fbe0fd0f4d91ee73bde22aeced756f0fc3c8 (patch)
tree5dcce00281f660ee7be6d28db892e5aa9ce89180
parent89506addb77510d985412c354c36fc27f467eb8c (diff)
Add multibranch project-type
This work was based on original work done by Joshua Harlow on top of older code from: https://github.com/abnamrocoesd/jenkins-job-builder/ Credit is due to `Joost van der Griendt` for doing this work. This builds on his work in that repo, and adjusts it so that it can get merged into upstream and released as a fully supported job type. SCM implementation is different than than normal SCM module, supporting: BitBucket, git, and GitHub in this initial patch. Change-Id: If50a54d282dd7d901c16edb9fe04874bdd83c9ef Co-Authored-By: Joshua Harlow <jxharlow@godaddy.com> Co-Authored-By: Sorin Sbarnea <ssbarnea@redhat.com> Co-Authored-By: Thanh Ha <zxiiro@linux.com> Signed-off-by: Sorin Sbarnea <ssbarnea@redhat.com> Signed-off-by: Thanh Ha <zxiiro@linux.com> Signed-off-by: Sorin Sbarnea <ssbarnea@redhat.com>
Notes
Notes (review): Code-Review+2: Darragh Bailey <daragh.bailey@gmail.com> Code-Review+2: Thanh Ha <zxiiro@gmail.com> Workflow+1: Sorin Sbarnea <ssbarnea@redhat.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Fri, 16 Mar 2018 16:26:19 +0000 Reviewed-on: https://review.openstack.org/403940 Project: openstack-infra/jenkins-job-builder Branch: refs/heads/master
-rw-r--r--doc/source/project_workflow_multibranch.rst7
-rw-r--r--jenkins_jobs/modules/project_multibranch.py508
-rw-r--r--jenkins_jobs/modules/scm.py6
-rw-r--r--setup.cfg2
-rw-r--r--tests/base.py5
-rw-r--r--tests/multibranch/__init__.py0
-rw-r--r--tests/multibranch/fixtures/multi_scm_full.xml84
-rw-r--r--tests/multibranch/fixtures/multi_scm_full.yaml21
-rw-r--r--tests/multibranch/fixtures/multibranch_defaults.xml60
-rw-r--r--tests/multibranch/fixtures/multibranch_defaults.yaml7
-rw-r--r--tests/multibranch/fixtures/scm_bitbucket_full.xml49
-rw-r--r--tests/multibranch/fixtures/scm_bitbucket_full.yaml7
-rw-r--r--tests/multibranch/fixtures/scm_bitbucket_minimal.xml48
-rw-r--r--tests/multibranch/fixtures/scm_bitbucket_minimal.yaml6
-rw-r--r--tests/multibranch/fixtures/scm_git_full.xml50
-rw-r--r--tests/multibranch/fixtures/scm_git_full.yaml8
-rw-r--r--tests/multibranch/fixtures/scm_git_minimal.xml50
-rw-r--r--tests/multibranch/fixtures/scm_git_minimal.yaml5
-rw-r--r--tests/multibranch/fixtures/scm_github_full.xml61
-rw-r--r--tests/multibranch/fixtures/scm_github_full.yaml12
-rw-r--r--tests/multibranch/fixtures/scm_github_minimal.xml59
-rw-r--r--tests/multibranch/fixtures/scm_github_minimal.yaml6
-rw-r--r--tests/multibranch/test_multibranch.py27
23 files changed, 1088 insertions, 0 deletions
diff --git a/doc/source/project_workflow_multibranch.rst b/doc/source/project_workflow_multibranch.rst
new file mode 100644
index 0000000..7e2c774
--- /dev/null
+++ b/doc/source/project_workflow_multibranch.rst
@@ -0,0 +1,7 @@
1.. _project_multibranch:
2
3Multibranch Pipeline Project
4============================
5
6.. automodule:: project_multibranch
7 :members:
diff --git a/jenkins_jobs/modules/project_multibranch.py b/jenkins_jobs/modules/project_multibranch.py
new file mode 100644
index 0000000..479f7ed
--- /dev/null
+++ b/jenkins_jobs/modules/project_multibranch.py
@@ -0,0 +1,508 @@
1# -*- coding: utf-8 -*-
2# Copyright (C) 2015 Joost van der Griendt <joostvdg@gmail.com>
3# Copyright (C) 2018 Sorin Sbarnea <ssbarnea@users.noreply.github.com>
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations
15# under the License.
16
17
18"""
19The Multibranch Pipeline project module handles creating Jenkins workflow
20projects.
21You may specify ``multibranch`` in the ``project-type`` attribute of
22the :ref:`Job` definition.
23
24Multibranch Pipeline implementantion in JJB is marked as **experimental**
25which means that there is no guarantee that its behavior (or configuration)
26will not change, even between minor releases.
27
28Plugins required:
29 * :jenkins-wiki:`Workflow Plugin <Workflow+Plugin>`.
30 * :jenkins-wiki:`Pipeline Multibranch Defaults Plugin
31 <Pipeline+Multibranch+Defaults+Plugin>` (optional)
32
33:Job Parameters:
34
35 * **scm** (`list`): The SCM definition.
36
37 * **bitbucket** (`dict`): Refer to
38 :func:`~bitbucket_scm <bitbucket_scm>` for documentation.
39
40 * **git** (`dict`): Refer to
41 :func:`~git_scm <git_scm>` for documentation.
42
43 * **github** (`dict`): Refer to
44 :func:`~github_scm <github_scm>` for documentation.
45
46 * **periodic-folder-trigger** (`str`): How often to scan for new branches
47 or pull/change requests. Valid values: 1m, 2m, 5m, 10m, 15m, 20m, 25m,
48 30m, 1h, 2h, 4h, 8h, 12h, 1d, 2d, 1w, 2w, 4w. (default none)
49 * **prune-dead-branches** (`bool`): If dead branches upon check should
50 result in their job being dropped. (default true)
51 * **number-to-keep** (`int`): How many builds should be kept.
52 (default '-1, all')
53 * **days-to-keep** (`int`): For how many days should a build be kept.
54 (default '-1, forever')
55
56Job examples:
57
58.. literalinclude:: /../../tests/multibranch/fixtures/multibranch_defaults.yaml
59
60.. literalinclude:: /../../tests/multibranch/fixtures/multi_scm_full.yaml
61
62"""
63import collections
64import logging
65import xml.etree.ElementTree as XML
66import jenkins_jobs.modules.base
67import jenkins_jobs.modules.helpers as helpers
68import uuid
69
70from jenkins_jobs.errors import InvalidAttributeError
71
72logger = logging.getLogger(str(__name__))
73
74
75class WorkflowMultiBranch(jenkins_jobs.modules.base.Base):
76 sequence = 0
77 multibranch_path = 'org.jenkinsci.plugins.workflow.multibranch'
78 jenkins_class = ''.join([multibranch_path, '.WorkflowMultiBranchProject'])
79 jenkins_factory_class = ''.join(
80 [multibranch_path, '.WorkflowBranchProjectFactory'])
81
82 def root_xml(self, data):
83 xml_parent = XML.Element(self.jenkins_class)
84 xml_parent.attrib['plugin'] = 'workflow-multibranch'
85 XML.SubElement(xml_parent, 'properties')
86
87 #########
88 # Views #
89 #########
90
91 views = XML.SubElement(xml_parent, 'views')
92 all_view = XML.SubElement(views, 'hudson.model.AllView')
93 all_view_mapping = [
94 ('', 'name', 'All'),
95 ('', 'filterExecutors', False),
96 ('', 'filterQueue', False),
97 ]
98 helpers.convert_mapping_to_xml(
99 all_view, {}, all_view_mapping, fail_required=True)
100
101 XML.SubElement(all_view, 'properties', {
102 'class': 'hudson.model.View$PropertyList'
103 })
104
105 XML.SubElement(all_view, 'owner', {
106 'class': self.jenkins_class,
107 'reference': '../../..'
108 })
109
110 XML.SubElement(xml_parent, 'viewsTabBar', {
111 'class': 'hudson.views.DefaultViewsTabBar'
112 })
113
114 ################
115 # Folder Views #
116 ################
117
118 folderViews = XML.SubElement(xml_parent, 'folderViews', {
119 'class': 'jenkins.branch.MultiBranchProjectViewHolder',
120 'plugin': 'branch-api',
121 })
122
123 XML.SubElement(folderViews, 'owner', {
124 'class': self.jenkins_class,
125 'reference': '../..'
126 })
127
128 ##################
129 # Health Metrics #
130 ##################
131
132 hm = XML.SubElement(xml_parent, 'healthMetrics')
133 hm_path = ('com.cloudbees.hudson.plugins.folder.health'
134 '.WorstChildHealthMetric')
135 hm_plugin = XML.SubElement(hm, hm_path, {
136 'plugin': 'cloudbees-folder',
137 })
138 XML.SubElement(hm_plugin, 'nonRecursive').text = 'false'
139
140 ########
141 # Icon #
142 ########
143
144 icon = XML.SubElement(xml_parent, 'icon', {
145 'class': 'jenkins.branch.MetadataActionFolderIcon',
146 'plugin': 'branch-api',
147 })
148 XML.SubElement(icon, 'owner', {
149 'class': self.jenkins_class,
150 'reference': '../..'
151 })
152
153 ########################
154 # Orphan Item Strategy #
155 ########################
156
157 ois_default_strategy = ('com.cloudbees.hudson.plugins.'
158 'folder.computed.DefaultOrphanedItemStrategy')
159 ois = XML.SubElement(
160 xml_parent, 'orphanedItemStrategy', {
161 'class': ois_default_strategy,
162 'plugin': 'cloudbees-folder',
163 }
164 )
165
166 ois_mapping = [
167 ('prune-dead-branches', 'pruneDeadBranches', True, [True, False]),
168 ('days-to-keep', 'daysToKeep', -1),
169 ('number-to-keep', 'numToKeep', -1),
170 ]
171 helpers.convert_mapping_to_xml(ois, data, ois_mapping)
172
173 ###########################
174 # Periodic Folder Trigger #
175 ###########################
176
177 triggers = XML.SubElement(xml_parent, 'triggers')
178
179 # Valid options for the periodic trigger interval.
180 pft_map = collections.OrderedDict([
181 ("1m", ("* * * * *", '60000')),
182 ("2m", ("*/2 * * * *", '120000')),
183 ("5m", ("*/5 * * * *", '300000')),
184 ("10m", ("H/6 * * * *", '600000')),
185 ("15m", ("H/6 * * * *", '900000')),
186 ("20m", ("H/3 * * * *", '1200000')),
187 ("25m", ("H/3 * * * *", '1500000')),
188 ("30m", ("H/2 * * * *", '1800000')),
189 ("1h", ("H * * * *", '3600000')),
190 ("2h", ("H * * * *", '7200000')),
191 ("4h", ("H * * * *", '14400000')),
192 ("8h", ("H * * * *", '28800000')),
193 ("12h", ("H H * * *", '43200000')),
194 ("1d", ("H H * * *", '86400000')),
195 ("2d", ("H H * * *", '172800000')),
196 ("1w", ("H H * * *", '604800000')),
197 ("2w", ("H H * * *", '1209600000')),
198 ("4w", ("H H * * *", '2419200000')),
199 ])
200
201 pft_val = data.get('periodic-folder-trigger')
202 if pft_val:
203 if not pft_map.get(pft_val):
204 raise InvalidAttributeError(
205 'periodic-folder-trigger',
206 pft_val,
207 pft_map.keys())
208
209 pft_path = (
210 'com.cloudbees.hudson.plugins.folder.computed.'
211 'PeriodicFolderTrigger')
212 pft = XML.SubElement(triggers, pft_path, {
213 'plugin': 'cloudbees-folder'
214 })
215 XML.SubElement(pft, 'spec').text = pft_map[pft_val][0]
216 XML.SubElement(pft, 'interval').text = pft_map[pft_val][1]
217
218 ###########
219 # Sources #
220 ###########
221
222 sources = XML.SubElement(xml_parent, 'sources', {
223 'class': 'jenkins.branch.MultiBranchProject$BranchSourceList',
224 'plugin': 'branch-api',
225 })
226 sources_data = XML.SubElement(sources, 'data')
227 XML.SubElement(sources, 'owner', {
228 'class': self.jenkins_class,
229 'reference': '../..',
230 })
231
232 valid_scm = [
233 'bitbucket',
234 'git',
235 'github',
236 ]
237 for scm_data in data.get('scm', None):
238 for scm in scm_data:
239 bs = XML.SubElement(
240 sources_data, 'jenkins.branch.BranchSource')
241
242 if scm == 'bitbucket':
243 bitbucket_scm(bs, scm_data[scm])
244
245 elif scm == 'git':
246 git_scm(bs, scm_data[scm])
247
248 elif scm == 'github':
249 github_scm(bs, scm_data[scm])
250
251 else:
252 raise InvalidAttributeError('scm', scm_data, valid_scm)
253
254 ###########
255 # Factory #
256 ###########
257
258 factory = XML.SubElement(xml_parent, 'factory', {
259 'class': self.jenkins_factory_class,
260 })
261 XML.SubElement(factory, 'owner', {
262 'class': self.jenkins_class,
263 'reference': '../..'
264 })
265 XML.SubElement(factory, 'scriptPath').text = 'Jenkinsfile'
266
267 return xml_parent
268
269
270class WorkflowMultiBranchDefaults(WorkflowMultiBranch):
271 jenkins_class = (
272 'org.jenkinsci.plugins.pipeline.multibranch'
273 '.defaults.PipelineMultiBranchDefaultsProject')
274 jenkins_factory_class = (
275 'org.jenkinsci.plugins.pipeline.multibranch'
276 '.defaults.PipelineBranchDefaultsProjectFactory')
277
278
279def bitbucket_scm(xml_parent, data):
280 """Configure BitBucket scm
281
282 Requires the :jenkins-wiki:`Bitbucket Branch Source Plugin
283 <Bitbucket+Branch+Source+Plugin>`.
284
285 :arg str credentials-id: The credential to use to scan BitBucket.
286 (required)
287 :arg str repo-owner: Specify the name of the Bitbucket Team or Bitbucket
288 User Account. (required)
289 :arg str repo: The BitBucket repo. (required)
290
291 Minimal Example:
292
293 .. literalinclude::
294 /../../tests/multibranch/fixtures/scm_bitbucket_minimal.yaml
295
296 Full Example:
297
298 .. literalinclude::
299 /../../tests/multibranch/fixtures/scm_bitbucket_full.yaml
300 """
301 source = XML.SubElement(xml_parent, 'source', {
302 'class': 'com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource',
303 'plugin': 'cloudbees-bitbucket-branch-source',
304 })
305 source_mapping = [
306 ('', 'id', str(uuid.uuid4())),
307 ('repo-owner', 'repoOwner', None),
308 ('repo', 'repository', None),
309 ]
310 helpers.convert_mapping_to_xml(
311 source, data, source_mapping, fail_required=True)
312
313 mapping_optional = [
314 ('credentials-id', 'credentialsId', None),
315 ]
316 helpers.convert_mapping_to_xml(
317 source, data, mapping_optional, fail_required=False)
318
319 XML.SubElement(source, 'traits')
320
321
322def git_scm(xml_parent, data):
323 """Configure Git SCM
324
325 Requires the :jenkins-wiki:`Git Plugin <Git+Plugin>`.
326
327 :arg str url: The git repo url. (required)
328 :arg str credentials-id: The credential to use to connect to the GIT repo.
329 (default '')
330
331 :arg bool discover-branches: Discovers branches on the repository.
332 (default true)
333 :arg bool ignore-on-push-notifications: If a job should not trigger upon
334 push notifications. (default false)
335
336 Minimal Example:
337
338 .. literalinclude:: /../../tests/multibranch/fixtures/scm_git_minimal.yaml
339
340 Full Example:
341
342 .. literalinclude:: /../../tests/multibranch/fixtures/scm_git_full.yaml
343 """
344 source = XML.SubElement(xml_parent, 'source', {
345 'class': 'jenkins.plugins.git.GitSCMSource',
346 'plugin': 'git',
347 })
348 source_mapping = [
349 ('', 'id', str(uuid.uuid4())),
350 ('url', 'remote', None),
351 ('credentials-id', 'credentialsId', ''),
352 ]
353 helpers.convert_mapping_to_xml(
354 source, data, source_mapping, fail_required=True)
355
356 ##########
357 # Traits #
358 ##########
359
360 traits_path = 'jenkins.plugins.git.traits'
361 traits = XML.SubElement(source, 'traits')
362
363 if data.get('discover-branches', True):
364 XML.SubElement(traits, ''.join([traits_path, '.BranchDiscoveryTrait']))
365
366 if data.get('ignore-on-push-notifications', False):
367 XML.SubElement(
368 traits, ''.join([traits_path, '.IgnoreOnPushNotificationTrait']))
369
370
371def github_scm(xml_parent, data):
372 """Configure GitHub SCM
373
374 Requires the :jenkins-wiki:`GitHub Branch Source Plugin
375 <GitHub+Branch+Source+Plugin>`.
376
377 :arg str api-uri: The GitHub API uri for hosted / on-site GitHub. Must
378 first be configured in Global Configuration. (default GitHub)
379 :arg str credentials-id: Credentials used to scan branches and pull
380 requests, check out sources and mark commit statuses. (optional)
381 :arg str repo-owner: Specify the name of the GitHub Organization or
382 GitHub User Account. (required)
383 :arg str repo: The GitHub repo. (required)
384
385 :arg str branch-discovery: Discovers branches on the repository.
386 Valid options: no-pr, only-pr, all, false. (default 'no-pr')
387 :arg str discover-pr-forks-strategy: Fork strategy. Valid options:
388 merge-current, current, both, false. (default 'merge-current')
389 :arg str discover-pr-forks-trust: Discovers pull requests where the origin
390 repository is a fork of the target repository.
391 Valid options: contributors, everyone, permission or nobody.
392 (default 'contributors')
393 :arg str discover-pr-origin: Discovers pull requests where the origin
394 repository is the same as the target repository.
395 Valid options: merge-current, current, both. (default 'merge-current')
396
397 Minimal Example:
398
399 .. literalinclude::
400 /../../tests/multibranch/fixtures/scm_github_minimal.yaml
401
402 Full Example:
403
404 .. literalinclude::
405 /../../tests/multibranch/fixtures/scm_github_full.yaml
406 """
407 github_path = 'org.jenkinsci.plugins.github_branch_source'
408 github_path_dscore = 'org.jenkinsci.plugins.github__branch__source'
409
410 source = XML.SubElement(xml_parent, 'source', {
411 'class': ''.join([github_path, '.GitHubSCMSource']),
412 'plugin': 'github-branch-source',
413 })
414 mapping = [
415 ('', 'id', str(uuid.uuid4())),
416 ('repo-owner', 'repoOwner', None),
417 ('repo', 'repository', None),
418 ]
419 helpers.convert_mapping_to_xml(
420 source, data, mapping, fail_required=True)
421
422 mapping_optional = [
423 ('api-uri', 'apiUri', None),
424 ('credentials-id', 'credentialsId', None),
425 ]
426 helpers.convert_mapping_to_xml(
427 source, data, mapping_optional, fail_required=False)
428
429 traits = XML.SubElement(source, 'traits')
430
431 # no-pr value is assumed if branch-discovery not mentioned.
432 if data.get('branch-discovery', 'no-pr'):
433 bd = XML.SubElement(traits, ''.join([
434 github_path_dscore, '.BranchDiscoveryTrait']))
435 bd_strategy = {
436 'no-pr': '1',
437 'only-pr': '2',
438 'all': '3',
439 }
440 bd_mapping = [
441 ('branch-discovery', 'strategyId', 'no-pr', bd_strategy)
442 ]
443 helpers.convert_mapping_to_xml(
444 bd, data, bd_mapping, fail_required=True)
445
446 if data.get('discover-pr-forks-strategy', 'merged-current'):
447 dprf = XML.SubElement(
448 traits, ''.join([
449 github_path_dscore, '.ForkPullRequestDiscoveryTrait'
450 ])
451 )
452 dprf_strategy = {
453 'merge-current': '1',
454 'current': '2',
455 'both': '3',
456 }
457 dprf_mapping = [
458 ('discover-pr-forks-strategy', 'strategyId', 'merge-current',
459 dprf_strategy)
460 ]
461 helpers.convert_mapping_to_xml(
462 dprf, data, dprf_mapping, fail_required=True)
463
464 trust = data.get('discover-pr-forks-trust', 'contributors')
465 trust_map = {
466 'contributors': ''.join([
467 github_path,
468 '.ForkPullRequestDiscoveryTrait$TrustContributors']),
469 'everyone': ''.join([
470 github_path,
471 '.ForkPullRequestDiscoveryTrait$TrustEveryone']),
472 'permission': ''.join([
473 github_path,
474 '.ForkPullRequestDiscoveryTrait$TrustPermission']),
475 'nobody': ''.join([
476 github_path,
477 '.ForkPullRequestDiscoveryTrait$TrustNobody']),
478 }
479 if trust not in trust_map:
480 raise InvalidAttributeError('discover-pr-forks-trust',
481 trust,
482 trust_map.keys())
483 XML.SubElement(dprf, 'trust').attrib['class'] = trust_map[trust]
484
485 dpro_strategy = data.get('discover-pr-origin', 'merge-current')
486 dpro = XML.SubElement(traits, ''.join([
487 github_path_dscore,
488 '.OriginPullRequestDiscoveryTrait'
489 ]))
490 dpro_strategy_map = {
491 'merge-current': '1',
492 'current': '2',
493 'both': '3',
494 }
495 if dpro_strategy not in dpro_strategy_map:
496 raise InvalidAttributeError('discover-pr-origin',
497 dpro_strategy,
498 dpro_strategy_map.keys())
499 if trust not in trust_map:
500 raise InvalidAttributeError('discover-pr-forks-trust',
501 trust,
502 trust_map.keys())
503 dpro_mapping = [
504 ('discover-pr-origin', 'strategyId', 'merge-current',
505 dpro_strategy_map)
506 ]
507 helpers.convert_mapping_to_xml(
508 dpro, data, dpro_mapping, fail_required=True)
diff --git a/jenkins_jobs/modules/scm.py b/jenkins_jobs/modules/scm.py
index 20abf45..70e9725 100644
--- a/jenkins_jobs/modules/scm.py
+++ b/jenkins_jobs/modules/scm.py
@@ -1377,6 +1377,12 @@ class SCM(jenkins_jobs.modules.base.Base):
1377 component_list_type = 'scm' 1377 component_list_type = 'scm'
1378 1378
1379 def gen_xml(self, xml_parent, data): 1379 def gen_xml(self, xml_parent, data):
1380
1381 # multibranch-pipeline scm implementation is incompatible with SCM
1382 if data.get('project-type') in ['multibranch', 'multibranch-defaults']:
1383 logging.debug("SCM Module skipped for multibranch project-type.")
1384 return
1385
1380 scms_parent = XML.Element('scms') 1386 scms_parent = XML.Element('scms')
1381 for scm in data.get('scm', []): 1387 for scm in data.get('scm', []):
1382 self.registry.dispatch('scm', scms_parent, scm) 1388 self.registry.dispatch('scm', scms_parent, scm)
diff --git a/setup.cfg b/setup.cfg
index 6a75197..d0bb95c 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -56,6 +56,8 @@ jenkins_jobs.projects =
56 freestyle=jenkins_jobs.modules.project_freestyle:Freestyle 56 freestyle=jenkins_jobs.modules.project_freestyle:Freestyle
57 matrix=jenkins_jobs.modules.project_matrix:Matrix 57 matrix=jenkins_jobs.modules.project_matrix:Matrix
58 maven=jenkins_jobs.modules.project_maven:Maven 58 maven=jenkins_jobs.modules.project_maven:Maven
59 multibranch=jenkins_jobs.modules.project_multibranch:WorkflowMultiBranch
60 multibranch-defaults=jenkins_jobs.modules.project_multibranch:WorkflowMultiBranchDefaults
59 multijob=jenkins_jobs.modules.project_multijob:MultiJob 61 multijob=jenkins_jobs.modules.project_multijob:MultiJob
60 pipeline=jenkins_jobs.modules.project_pipeline:Pipeline 62 pipeline=jenkins_jobs.modules.project_pipeline:Pipeline
61 workflow=jenkins_jobs.modules.project_workflow:Workflow 63 workflow=jenkins_jobs.modules.project_workflow:Workflow
diff --git a/tests/base.py b/tests/base.py
index e40c98a..855f2e7 100644
--- a/tests/base.py
+++ b/tests/base.py
@@ -41,6 +41,7 @@ from jenkins_jobs.modules import project_externaljob
41from jenkins_jobs.modules import project_flow 41from jenkins_jobs.modules import project_flow
42from jenkins_jobs.modules import project_matrix 42from jenkins_jobs.modules import project_matrix
43from jenkins_jobs.modules import project_maven 43from jenkins_jobs.modules import project_maven
44from jenkins_jobs.modules import project_multibranch
44from jenkins_jobs.modules import project_multijob 45from jenkins_jobs.modules import project_multijob
45from jenkins_jobs.modules import view_list 46from jenkins_jobs.modules import view_list
46from jenkins_jobs.modules import view_pipeline 47from jenkins_jobs.modules import view_pipeline
@@ -188,6 +189,10 @@ class BaseScenariosTestCase(testscenarios.TestWithScenarios, BaseTestCase):
188 project = project_flow.Flow(registry) 189 project = project_flow.Flow(registry)
189 elif (yaml_content['project-type'] == "multijob"): 190 elif (yaml_content['project-type'] == "multijob"):
190 project = project_multijob.MultiJob(registry) 191 project = project_multijob.MultiJob(registry)
192 elif (yaml_content['project-type'] == "multibranch"):
193 project = project_multibranch.WorkflowMultiBranch(registry)
194 elif (yaml_content['project-type'] == "multibranch-defaults"):
195 project = project_multibranch.WorkflowMultiBranchDefaults(registry) # noqa
191 elif (yaml_content['project-type'] == "externaljob"): 196 elif (yaml_content['project-type'] == "externaljob"):
192 project = project_externaljob.ExternalJob(registry) 197 project = project_externaljob.ExternalJob(registry)
193 198
diff --git a/tests/multibranch/__init__.py b/tests/multibranch/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/multibranch/__init__.py
diff --git a/tests/multibranch/fixtures/multi_scm_full.xml b/tests/multibranch/fixtures/multi_scm_full.xml
new file mode 100644
index 0000000..c54a4c5
--- /dev/null
+++ b/tests/multibranch/fixtures/multi_scm_full.xml
@@ -0,0 +1,84 @@
1<?xml version="1.0" encoding="utf-8"?>
2<org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject plugin="workflow-multibranch">
3 <properties/>
4 <views>
5 <hudson.model.AllView>
6 <name>All</name>
7 <filterExecutors>false</filterExecutors>
8 <filterQueue>false</filterQueue>
9 <properties class="hudson.model.View$PropertyList"/>
10 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../../.."/>
11 </hudson.model.AllView>
12 </views>
13 <viewsTabBar class="hudson.views.DefaultViewsTabBar"/>
14 <folderViews class="jenkins.branch.MultiBranchProjectViewHolder" plugin="branch-api">
15 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
16 </folderViews>
17 <healthMetrics>
18 <com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric plugin="cloudbees-folder">
19 <nonRecursive>false</nonRecursive>
20 </com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric>
21 </healthMetrics>
22 <icon class="jenkins.branch.MetadataActionFolderIcon" plugin="branch-api">
23 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
24 </icon>
25 <orphanedItemStrategy class="com.cloudbees.hudson.plugins.folder.computed.DefaultOrphanedItemStrategy" plugin="cloudbees-folder">
26 <pruneDeadBranches>true</pruneDeadBranches>
27 <daysToKeep>10</daysToKeep>
28 <numToKeep>10</numToKeep>
29 </orphanedItemStrategy>
30 <triggers>
31 <com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger plugin="cloudbees-folder">
32 <spec>H H * * *</spec>
33 <interval>86400000</interval>
34 </com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger>
35 </triggers>
36 <sources class="jenkins.branch.MultiBranchProject$BranchSourceList" plugin="branch-api">
37 <data>
38 <jenkins.branch.BranchSource>
39 <source class="com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource" plugin="cloudbees-bitbucket-branch-source">
40 <id>1-1-1-1-1</id>
41 <repoOwner>SANDBOX</repoOwner>
42 <repository>test</repository>
43 <credentialsId>secret</credentialsId>
44 <traits/>
45 </source>
46 </jenkins.branch.BranchSource>
47 <jenkins.branch.BranchSource>
48 <source class="jenkins.plugins.git.GitSCMSource" plugin="git">
49 <id>1-1-1-1-1</id>
50 <remote>https://example.com/jonhndoe/keep-frontend.git</remote>
51 <credentialsId>secret</credentialsId>
52 <traits>
53 <jenkins.plugins.git.traits.BranchDiscoveryTrait/>
54 </traits>
55 </source>
56 </jenkins.branch.BranchSource>
57 <jenkins.branch.BranchSource>
58 <source class="org.jenkinsci.plugins.github_branch_source.GitHubSCMSource" plugin="github-branch-source">
59 <id>1-1-1-1-1</id>
60 <repoOwner>johndoe</repoOwner>
61 <repository>foo</repository>
62 <credentialsId>secret</credentialsId>
63 <traits>
64 <org.jenkinsci.plugins.github__branch__source.BranchDiscoveryTrait>
65 <strategyId>1</strategyId>
66 </org.jenkinsci.plugins.github__branch__source.BranchDiscoveryTrait>
67 <org.jenkinsci.plugins.github__branch__source.ForkPullRequestDiscoveryTrait>
68 <strategyId>1</strategyId>
69 <trust class="org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait$TrustContributors"/>
70 </org.jenkinsci.plugins.github__branch__source.ForkPullRequestDiscoveryTrait>
71 <org.jenkinsci.plugins.github__branch__source.OriginPullRequestDiscoveryTrait>
72 <strategyId>1</strategyId>
73 </org.jenkinsci.plugins.github__branch__source.OriginPullRequestDiscoveryTrait>
74 </traits>
75 </source>
76 </jenkins.branch.BranchSource>
77 </data>
78 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
79 </sources>
80 <factory class="org.jenkinsci.plugins.workflow.multibranch.WorkflowBranchProjectFactory">
81 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
82 <scriptPath>Jenkinsfile</scriptPath>
83 </factory>
84</org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject>
diff --git a/tests/multibranch/fixtures/multi_scm_full.yaml b/tests/multibranch/fixtures/multi_scm_full.yaml
new file mode 100644
index 0000000..f7739c4
--- /dev/null
+++ b/tests/multibranch/fixtures/multi_scm_full.yaml
@@ -0,0 +1,21 @@
1name: 'demo-multibranch-multi-scm-full'
2description: 'Workflow demo'
3
4project-type: multibranch
5
6periodic-folder-trigger: 1d
7prune-dead-branches: True
8number-to-keep: '10'
9days-to-keep: '10'
10scm:
11 - bitbucket:
12 repo-owner: 'SANDBOX'
13 repo: 'test'
14 credentials-id: 'secret'
15 - git:
16 url: 'https://example.com/jonhndoe/keep-frontend.git'
17 credentials-id: 'secret'
18 - github:
19 repo: 'foo'
20 repo-owner: 'johndoe'
21 credentials-id: 'secret'
diff --git a/tests/multibranch/fixtures/multibranch_defaults.xml b/tests/multibranch/fixtures/multibranch_defaults.xml
new file mode 100644
index 0000000..b192ae8
--- /dev/null
+++ b/tests/multibranch/fixtures/multibranch_defaults.xml
@@ -0,0 +1,60 @@
1<?xml version="1.0" encoding="utf-8"?>
2<org.jenkinsci.plugins.pipeline.multibranch.defaults.PipelineMultiBranchDefaultsProject plugin="workflow-multibranch">
3 <properties/>
4 <views>
5 <hudson.model.AllView>
6 <name>All</name>
7 <filterExecutors>false</filterExecutors>
8 <filterQueue>false</filterQueue>
9 <properties class="hudson.model.View$PropertyList"/>
10 <owner class="org.jenkinsci.plugins.pipeline.multibranch.defaults.PipelineMultiBranchDefaultsProject" reference="../../.."/>
11 </hudson.model.AllView>
12 </views>
13 <viewsTabBar class="hudson.views.DefaultViewsTabBar"/>
14 <folderViews class="jenkins.branch.MultiBranchProjectViewHolder" plugin="branch-api">
15 <owner class="org.jenkinsci.plugins.pipeline.multibranch.defaults.PipelineMultiBranchDefaultsProject" reference="../.."/>
16 </folderViews>
17 <healthMetrics>
18 <com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric plugin="cloudbees-folder">
19 <nonRecursive>false</nonRecursive>
20 </com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric>
21 </healthMetrics>
22 <icon class="jenkins.branch.MetadataActionFolderIcon" plugin="branch-api">
23 <owner class="org.jenkinsci.plugins.pipeline.multibranch.defaults.PipelineMultiBranchDefaultsProject" reference="../.."/>
24 </icon>
25 <orphanedItemStrategy class="com.cloudbees.hudson.plugins.folder.computed.DefaultOrphanedItemStrategy" plugin="cloudbees-folder">
26 <pruneDeadBranches>true</pruneDeadBranches>
27 <daysToKeep>-1</daysToKeep>
28 <numToKeep>-1</numToKeep>
29 </orphanedItemStrategy>
30 <triggers/>
31 <sources class="jenkins.branch.MultiBranchProject$BranchSourceList" plugin="branch-api">
32 <data>
33 <jenkins.branch.BranchSource>
34 <source class="org.jenkinsci.plugins.github_branch_source.GitHubSCMSource" plugin="github-branch-source">
35 <id>1-1-1-1-1</id>
36 <repoOwner>johndoe</repoOwner>
37 <repository>foo</repository>
38 <credentialsId>secret</credentialsId>
39 <traits>
40 <org.jenkinsci.plugins.github__branch__source.BranchDiscoveryTrait>
41 <strategyId>1</strategyId>
42 </org.jenkinsci.plugins.github__branch__source.BranchDiscoveryTrait>
43 <org.jenkinsci.plugins.github__branch__source.ForkPullRequestDiscoveryTrait>
44 <strategyId>1</strategyId>
45 <trust class="org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait$TrustContributors"/>
46 </org.jenkinsci.plugins.github__branch__source.ForkPullRequestDiscoveryTrait>
47 <org.jenkinsci.plugins.github__branch__source.OriginPullRequestDiscoveryTrait>
48 <strategyId>1</strategyId>
49 </org.jenkinsci.plugins.github__branch__source.OriginPullRequestDiscoveryTrait>
50 </traits>
51 </source>
52 </jenkins.branch.BranchSource>
53 </data>
54 <owner class="org.jenkinsci.plugins.pipeline.multibranch.defaults.PipelineMultiBranchDefaultsProject" reference="../.."/>
55 </sources>
56 <factory class="org.jenkinsci.plugins.pipeline.multibranch.defaults.PipelineBranchDefaultsProjectFactory">
57 <owner class="org.jenkinsci.plugins.pipeline.multibranch.defaults.PipelineMultiBranchDefaultsProject" reference="../.."/>
58 <scriptPath>Jenkinsfile</scriptPath>
59 </factory>
60</org.jenkinsci.plugins.pipeline.multibranch.defaults.PipelineMultiBranchDefaultsProject>
diff --git a/tests/multibranch/fixtures/multibranch_defaults.yaml b/tests/multibranch/fixtures/multibranch_defaults.yaml
new file mode 100644
index 0000000..51e41be
--- /dev/null
+++ b/tests/multibranch/fixtures/multibranch_defaults.yaml
@@ -0,0 +1,7 @@
1name: 'demo-multibranch-defaults'
2project-type: multibranch-defaults
3scm:
4 - github:
5 repo: 'foo'
6 repo-owner: 'johndoe'
7 credentials-id: 'secret'
diff --git a/tests/multibranch/fixtures/scm_bitbucket_full.xml b/tests/multibranch/fixtures/scm_bitbucket_full.xml
new file mode 100644
index 0000000..f1a7342
--- /dev/null
+++ b/tests/multibranch/fixtures/scm_bitbucket_full.xml
@@ -0,0 +1,49 @@
1<?xml version="1.0" encoding="utf-8"?>
2<org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject plugin="workflow-multibranch">
3 <properties/>
4 <views>
5 <hudson.model.AllView>
6 <name>All</name>
7 <filterExecutors>false</filterExecutors>
8 <filterQueue>false</filterQueue>
9 <properties class="hudson.model.View$PropertyList"/>
10 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../../.."/>
11 </hudson.model.AllView>
12 </views>
13 <viewsTabBar class="hudson.views.DefaultViewsTabBar"/>
14 <folderViews class="jenkins.branch.MultiBranchProjectViewHolder" plugin="branch-api">
15 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
16 </folderViews>
17 <healthMetrics>
18 <com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric plugin="cloudbees-folder">
19 <nonRecursive>false</nonRecursive>
20 </com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric>
21 </healthMetrics>
22 <icon class="jenkins.branch.MetadataActionFolderIcon" plugin="branch-api">
23 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
24 </icon>
25 <orphanedItemStrategy class="com.cloudbees.hudson.plugins.folder.computed.DefaultOrphanedItemStrategy" plugin="cloudbees-folder">
26 <pruneDeadBranches>true</pruneDeadBranches>
27 <daysToKeep>-1</daysToKeep>
28 <numToKeep>-1</numToKeep>
29 </orphanedItemStrategy>
30 <triggers/>
31 <sources class="jenkins.branch.MultiBranchProject$BranchSourceList" plugin="branch-api">
32 <data>
33 <jenkins.branch.BranchSource>
34 <source class="com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource" plugin="cloudbees-bitbucket-branch-source">
35 <id>1-1-1-1-1</id>
36 <repoOwner>SANDBOX</repoOwner>
37 <repository>test</repository>
38 <credentialsId>secret</credentialsId>
39 <traits/>
40 </source>
41 </jenkins.branch.BranchSource>
42 </data>
43 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
44 </sources>
45 <factory class="org.jenkinsci.plugins.workflow.multibranch.WorkflowBranchProjectFactory">
46 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
47 <scriptPath>Jenkinsfile</scriptPath>
48 </factory>
49</org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject>
diff --git a/tests/multibranch/fixtures/scm_bitbucket_full.yaml b/tests/multibranch/fixtures/scm_bitbucket_full.yaml
new file mode 100644
index 0000000..b9d3ca1
--- /dev/null
+++ b/tests/multibranch/fixtures/scm_bitbucket_full.yaml
@@ -0,0 +1,7 @@
1name: 'demo-multibranch-bitbucket-min'
2project-type: multibranch
3scm:
4 - bitbucket:
5 credentials-id: 'secret'
6 repo-owner: 'SANDBOX'
7 repo: 'test'
diff --git a/tests/multibranch/fixtures/scm_bitbucket_minimal.xml b/tests/multibranch/fixtures/scm_bitbucket_minimal.xml
new file mode 100644
index 0000000..b2a7d6b
--- /dev/null
+++ b/tests/multibranch/fixtures/scm_bitbucket_minimal.xml
@@ -0,0 +1,48 @@
1<?xml version="1.0" encoding="utf-8"?>
2<org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject plugin="workflow-multibranch">
3 <properties/>
4 <views>
5 <hudson.model.AllView>
6 <name>All</name>
7 <filterExecutors>false</filterExecutors>
8 <filterQueue>false</filterQueue>
9 <properties class="hudson.model.View$PropertyList"/>
10 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../../.."/>
11 </hudson.model.AllView>
12 </views>
13 <viewsTabBar class="hudson.views.DefaultViewsTabBar"/>
14 <folderViews class="jenkins.branch.MultiBranchProjectViewHolder" plugin="branch-api">
15 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
16 </folderViews>
17 <healthMetrics>
18 <com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric plugin="cloudbees-folder">
19 <nonRecursive>false</nonRecursive>
20 </com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric>
21 </healthMetrics>
22 <icon class="jenkins.branch.MetadataActionFolderIcon" plugin="branch-api">
23 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
24 </icon>
25 <orphanedItemStrategy class="com.cloudbees.hudson.plugins.folder.computed.DefaultOrphanedItemStrategy" plugin="cloudbees-folder">
26 <pruneDeadBranches>true</pruneDeadBranches>
27 <daysToKeep>-1</daysToKeep>
28 <numToKeep>-1</numToKeep>
29 </orphanedItemStrategy>
30 <triggers/>
31 <sources class="jenkins.branch.MultiBranchProject$BranchSourceList" plugin="branch-api">
32 <data>
33 <jenkins.branch.BranchSource>
34 <source class="com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource" plugin="cloudbees-bitbucket-branch-source">
35 <id>1-1-1-1-1</id>
36 <repoOwner>SANDBOX</repoOwner>
37 <repository>test</repository>
38 <traits/>
39 </source>
40 </jenkins.branch.BranchSource>
41 </data>
42 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
43 </sources>
44 <factory class="org.jenkinsci.plugins.workflow.multibranch.WorkflowBranchProjectFactory">
45 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
46 <scriptPath>Jenkinsfile</scriptPath>
47 </factory>
48</org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject>
diff --git a/tests/multibranch/fixtures/scm_bitbucket_minimal.yaml b/tests/multibranch/fixtures/scm_bitbucket_minimal.yaml
new file mode 100644
index 0000000..8a2a6b5
--- /dev/null
+++ b/tests/multibranch/fixtures/scm_bitbucket_minimal.yaml
@@ -0,0 +1,6 @@
1name: 'demo-multibranch-bitbucket-min'
2project-type: multibranch
3scm:
4 - bitbucket:
5 repo-owner: 'SANDBOX'
6 repo: 'test'
diff --git a/tests/multibranch/fixtures/scm_git_full.xml b/tests/multibranch/fixtures/scm_git_full.xml
new file mode 100644
index 0000000..42aa899
--- /dev/null
+++ b/tests/multibranch/fixtures/scm_git_full.xml
@@ -0,0 +1,50 @@
1<?xml version="1.0" encoding="utf-8"?>
2<org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject plugin="workflow-multibranch">
3 <properties/>
4 <views>
5 <hudson.model.AllView>
6 <name>All</name>
7 <filterExecutors>false</filterExecutors>
8 <filterQueue>false</filterQueue>
9 <properties class="hudson.model.View$PropertyList"/>
10 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../../.."/>
11 </hudson.model.AllView>
12 </views>
13 <viewsTabBar class="hudson.views.DefaultViewsTabBar"/>
14 <folderViews class="jenkins.branch.MultiBranchProjectViewHolder" plugin="branch-api">
15 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
16 </folderViews>
17 <healthMetrics>
18 <com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric plugin="cloudbees-folder">
19 <nonRecursive>false</nonRecursive>
20 </com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric>
21 </healthMetrics>
22 <icon class="jenkins.branch.MetadataActionFolderIcon" plugin="branch-api">
23 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
24 </icon>
25 <orphanedItemStrategy class="com.cloudbees.hudson.plugins.folder.computed.DefaultOrphanedItemStrategy" plugin="cloudbees-folder">
26 <pruneDeadBranches>true</pruneDeadBranches>
27 <daysToKeep>-1</daysToKeep>
28 <numToKeep>-1</numToKeep>
29 </orphanedItemStrategy>
30 <triggers/>
31 <sources class="jenkins.branch.MultiBranchProject$BranchSourceList" plugin="branch-api">
32 <data>
33 <jenkins.branch.BranchSource>
34 <source class="jenkins.plugins.git.GitSCMSource" plugin="git">
35 <id>1-1-1-1-1</id>
36 <remote>https://example.com/jonhndoe/keep-frontend.git</remote>
37 <credentialsId>secret</credentialsId>
38 <traits>
39 <jenkins.plugins.git.traits.IgnoreOnPushNotificationTrait/>
40 </traits>
41 </source>
42 </jenkins.branch.BranchSource>
43 </data>
44 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
45 </sources>
46 <factory class="org.jenkinsci.plugins.workflow.multibranch.WorkflowBranchProjectFactory">
47 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
48 <scriptPath>Jenkinsfile</scriptPath>
49 </factory>
50</org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject>
diff --git a/tests/multibranch/fixtures/scm_git_full.yaml b/tests/multibranch/fixtures/scm_git_full.yaml
new file mode 100644
index 0000000..a8087cf
--- /dev/null
+++ b/tests/multibranch/fixtures/scm_git_full.yaml
@@ -0,0 +1,8 @@
1name: 'demo-multibranch-git-min'
2project-type: multibranch
3scm:
4 - git:
5 url: 'https://example.com/jonhndoe/keep-frontend.git'
6 credentials-id: secret
7 discover-branches: false
8 ignore-on-push-notifications: true
diff --git a/tests/multibranch/fixtures/scm_git_minimal.xml b/tests/multibranch/fixtures/scm_git_minimal.xml
new file mode 100644
index 0000000..d7a5fba
--- /dev/null
+++ b/tests/multibranch/fixtures/scm_git_minimal.xml
@@ -0,0 +1,50 @@
1<?xml version="1.0" encoding="utf-8"?>
2<org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject plugin="workflow-multibranch">
3 <properties/>
4 <views>
5 <hudson.model.AllView>
6 <name>All</name>
7 <filterExecutors>false</filterExecutors>
8 <filterQueue>false</filterQueue>
9 <properties class="hudson.model.View$PropertyList"/>
10 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../../.."/>
11 </hudson.model.AllView>
12 </views>
13 <viewsTabBar class="hudson.views.DefaultViewsTabBar"/>
14 <folderViews class="jenkins.branch.MultiBranchProjectViewHolder" plugin="branch-api">
15 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
16 </folderViews>
17 <healthMetrics>
18 <com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric plugin="cloudbees-folder">
19 <nonRecursive>false</nonRecursive>
20 </com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric>
21 </healthMetrics>
22 <icon class="jenkins.branch.MetadataActionFolderIcon" plugin="branch-api">
23 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
24 </icon>
25 <orphanedItemStrategy class="com.cloudbees.hudson.plugins.folder.computed.DefaultOrphanedItemStrategy" plugin="cloudbees-folder">
26 <pruneDeadBranches>true</pruneDeadBranches>
27 <daysToKeep>-1</daysToKeep>
28 <numToKeep>-1</numToKeep>
29 </orphanedItemStrategy>
30 <triggers/>
31 <sources class="jenkins.branch.MultiBranchProject$BranchSourceList" plugin="branch-api">
32 <data>
33 <jenkins.branch.BranchSource>
34 <source class="jenkins.plugins.git.GitSCMSource" plugin="git">
35 <id>1-1-1-1-1</id>
36 <remote>https://example.com/jonhndoe/keep-frontend.git</remote>
37 <credentialsId/>
38 <traits>
39 <jenkins.plugins.git.traits.BranchDiscoveryTrait/>
40 </traits>
41 </source>
42 </jenkins.branch.BranchSource>
43 </data>
44 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
45 </sources>
46 <factory class="org.jenkinsci.plugins.workflow.multibranch.WorkflowBranchProjectFactory">
47 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
48 <scriptPath>Jenkinsfile</scriptPath>
49 </factory>
50</org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject>
diff --git a/tests/multibranch/fixtures/scm_git_minimal.yaml b/tests/multibranch/fixtures/scm_git_minimal.yaml
new file mode 100644
index 0000000..2936d60
--- /dev/null
+++ b/tests/multibranch/fixtures/scm_git_minimal.yaml
@@ -0,0 +1,5 @@
1name: 'demo-multibranch-git-min'
2project-type: multibranch
3scm:
4 - git:
5 url: 'https://example.com/jonhndoe/keep-frontend.git'
diff --git a/tests/multibranch/fixtures/scm_github_full.xml b/tests/multibranch/fixtures/scm_github_full.xml
new file mode 100644
index 0000000..b61d497
--- /dev/null
+++ b/tests/multibranch/fixtures/scm_github_full.xml
@@ -0,0 +1,61 @@
1<?xml version="1.0" encoding="utf-8"?>
2<org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject plugin="workflow-multibranch">
3 <properties/>
4 <views>
5 <hudson.model.AllView>
6 <name>All</name>
7 <filterExecutors>false</filterExecutors>
8 <filterQueue>false</filterQueue>
9 <properties class="hudson.model.View$PropertyList"/>
10 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../../.."/>
11 </hudson.model.AllView>
12 </views>
13 <viewsTabBar class="hudson.views.DefaultViewsTabBar"/>
14 <folderViews class="jenkins.branch.MultiBranchProjectViewHolder" plugin="branch-api">
15 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
16 </folderViews>
17 <healthMetrics>
18 <com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric plugin="cloudbees-folder">
19 <nonRecursive>false</nonRecursive>
20 </com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric>
21 </healthMetrics>
22 <icon class="jenkins.branch.MetadataActionFolderIcon" plugin="branch-api">
23 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
24 </icon>
25 <orphanedItemStrategy class="com.cloudbees.hudson.plugins.folder.computed.DefaultOrphanedItemStrategy" plugin="cloudbees-folder">
26 <pruneDeadBranches>true</pruneDeadBranches>
27 <daysToKeep>-1</daysToKeep>
28 <numToKeep>-1</numToKeep>
29 </orphanedItemStrategy>
30 <triggers/>
31 <sources class="jenkins.branch.MultiBranchProject$BranchSourceList" plugin="branch-api">
32 <data>
33 <jenkins.branch.BranchSource>
34 <source class="org.jenkinsci.plugins.github_branch_source.GitHubSCMSource" plugin="github-branch-source">
35 <id>1-1-1-1-1</id>
36 <repoOwner>example-owner</repoOwner>
37 <repository>example-repo</repository>
38 <apiUri>http://example.org/github</apiUri>
39 <credentialsId>example-credential</credentialsId>
40 <traits>
41 <org.jenkinsci.plugins.github__branch__source.BranchDiscoveryTrait>
42 <strategyId>3</strategyId>
43 </org.jenkinsci.plugins.github__branch__source.BranchDiscoveryTrait>
44 <org.jenkinsci.plugins.github__branch__source.ForkPullRequestDiscoveryTrait>
45 <strategyId>3</strategyId>
46 <trust class="org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait$TrustEveryone"/>
47 </org.jenkinsci.plugins.github__branch__source.ForkPullRequestDiscoveryTrait>
48 <org.jenkinsci.plugins.github__branch__source.OriginPullRequestDiscoveryTrait>
49 <strategyId>3</strategyId>
50 </org.jenkinsci.plugins.github__branch__source.OriginPullRequestDiscoveryTrait>
51 </traits>
52 </source>
53 </jenkins.branch.BranchSource>
54 </data>
55 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
56 </sources>
57 <factory class="org.jenkinsci.plugins.workflow.multibranch.WorkflowBranchProjectFactory">
58 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
59 <scriptPath>Jenkinsfile</scriptPath>
60 </factory>
61</org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject>
diff --git a/tests/multibranch/fixtures/scm_github_full.yaml b/tests/multibranch/fixtures/scm_github_full.yaml
new file mode 100644
index 0000000..157d429
--- /dev/null
+++ b/tests/multibranch/fixtures/scm_github_full.yaml
@@ -0,0 +1,12 @@
1name: scm-github-full
2project-type: multibranch
3scm:
4 - github:
5 api-uri: http://example.org/github
6 repo: example-repo
7 repo-owner: example-owner
8 credentials-id: example-credential
9 branch-discovery: all
10 discover-pr-forks-strategy: both
11 discover-pr-forks-trust: everyone
12 discover-pr-origin: both
diff --git a/tests/multibranch/fixtures/scm_github_minimal.xml b/tests/multibranch/fixtures/scm_github_minimal.xml
new file mode 100644
index 0000000..4b75b30
--- /dev/null
+++ b/tests/multibranch/fixtures/scm_github_minimal.xml
@@ -0,0 +1,59 @@
1<?xml version="1.0" encoding="utf-8"?>
2<org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject plugin="workflow-multibranch">
3 <properties/>
4 <views>
5 <hudson.model.AllView>
6 <name>All</name>
7 <filterExecutors>false</filterExecutors>
8 <filterQueue>false</filterQueue>
9 <properties class="hudson.model.View$PropertyList"/>
10 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../../.."/>
11 </hudson.model.AllView>
12 </views>
13 <viewsTabBar class="hudson.views.DefaultViewsTabBar"/>
14 <folderViews class="jenkins.branch.MultiBranchProjectViewHolder" plugin="branch-api">
15 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
16 </folderViews>
17 <healthMetrics>
18 <com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric plugin="cloudbees-folder">
19 <nonRecursive>false</nonRecursive>
20 </com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric>
21 </healthMetrics>
22 <icon class="jenkins.branch.MetadataActionFolderIcon" plugin="branch-api">
23 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
24 </icon>
25 <orphanedItemStrategy class="com.cloudbees.hudson.plugins.folder.computed.DefaultOrphanedItemStrategy" plugin="cloudbees-folder">
26 <pruneDeadBranches>true</pruneDeadBranches>
27 <daysToKeep>-1</daysToKeep>
28 <numToKeep>-1</numToKeep>
29 </orphanedItemStrategy>
30 <triggers/>
31 <sources class="jenkins.branch.MultiBranchProject$BranchSourceList" plugin="branch-api">
32 <data>
33 <jenkins.branch.BranchSource>
34 <source class="org.jenkinsci.plugins.github_branch_source.GitHubSCMSource" plugin="github-branch-source">
35 <id>1-1-1-1-1</id>
36 <repoOwner>johndoe</repoOwner>
37 <repository>foo</repository>
38 <traits>
39 <org.jenkinsci.plugins.github__branch__source.BranchDiscoveryTrait>
40 <strategyId>1</strategyId>
41 </org.jenkinsci.plugins.github__branch__source.BranchDiscoveryTrait>
42 <org.jenkinsci.plugins.github__branch__source.ForkPullRequestDiscoveryTrait>
43 <strategyId>1</strategyId>
44 <trust class="org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait$TrustContributors"/>
45 </org.jenkinsci.plugins.github__branch__source.ForkPullRequestDiscoveryTrait>
46 <org.jenkinsci.plugins.github__branch__source.OriginPullRequestDiscoveryTrait>
47 <strategyId>1</strategyId>
48 </org.jenkinsci.plugins.github__branch__source.OriginPullRequestDiscoveryTrait>
49 </traits>
50 </source>
51 </jenkins.branch.BranchSource>
52 </data>
53 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
54 </sources>
55 <factory class="org.jenkinsci.plugins.workflow.multibranch.WorkflowBranchProjectFactory">
56 <owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
57 <scriptPath>Jenkinsfile</scriptPath>
58 </factory>
59</org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject>
diff --git a/tests/multibranch/fixtures/scm_github_minimal.yaml b/tests/multibranch/fixtures/scm_github_minimal.yaml
new file mode 100644
index 0000000..9a9d799
--- /dev/null
+++ b/tests/multibranch/fixtures/scm_github_minimal.yaml
@@ -0,0 +1,6 @@
1name: 'demo-multibranch-github-min'
2project-type: multibranch
3scm:
4 - github:
5 repo: 'foo'
6 repo-owner: 'johndoe'
diff --git a/tests/multibranch/test_multibranch.py b/tests/multibranch/test_multibranch.py
new file mode 100644
index 0000000..6a1cca0
--- /dev/null
+++ b/tests/multibranch/test_multibranch.py
@@ -0,0 +1,27 @@
1#
2# Copyright (c) 2018 Sorin Sbarnea <ssbarnea@users.noreply.github.com>
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from tests import base
17import mock
18import os
19from jenkins_jobs.modules import project_multibranch
20
21
22@mock.patch('uuid.uuid4', mock.Mock(return_value='1-1-1-1-1'))
23class TestCaseMultibranchPipeline(base.BaseScenariosTestCase):
24 fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
25 scenarios = base.get_scenarios(fixtures_path)
26 default_config_file = '/dev/null'
27 klass = project_multibranch.WorkflowMultiBranch