Browse Source

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>
tags/2.0.4
Joost van der Griendt 2 years ago
parent
commit
efc5fbe0fd

+ 7
- 0
doc/source/project_workflow_multibranch.rst View File

@@ -0,0 +1,7 @@
1
+.. _project_multibranch:
2
+
3
+Multibranch Pipeline Project
4
+============================
5
+
6
+.. automodule:: project_multibranch
7
+   :members:

+ 508
- 0
jenkins_jobs/modules/project_multibranch.py View File

@@ -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
+"""
19
+The Multibranch Pipeline project module handles creating Jenkins workflow
20
+projects.
21
+You may specify ``multibranch`` in the ``project-type`` attribute of
22
+the :ref:`Job` definition.
23
+
24
+Multibranch Pipeline implementantion in JJB is marked as **experimental**
25
+which means that there is no guarantee that its behavior (or configuration)
26
+will not change, even between minor releases.
27
+
28
+Plugins 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
+
56
+Job examples:
57
+
58
+.. literalinclude:: /../../tests/multibranch/fixtures/multibranch_defaults.yaml
59
+
60
+.. literalinclude:: /../../tests/multibranch/fixtures/multi_scm_full.yaml
61
+
62
+"""
63
+import collections
64
+import logging
65
+import xml.etree.ElementTree as XML
66
+import jenkins_jobs.modules.base
67
+import jenkins_jobs.modules.helpers as helpers
68
+import uuid
69
+
70
+from jenkins_jobs.errors import InvalidAttributeError
71
+
72
+logger = logging.getLogger(str(__name__))
73
+
74
+
75
+class 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
+
270
+class 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
+
279
+def 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
+
322
+def 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
+
371
+def 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)

+ 6
- 0
jenkins_jobs/modules/scm.py View File

@@ -1377,6 +1377,12 @@ class SCM(jenkins_jobs.modules.base.Base):
1377 1377
     component_list_type = 'scm'
1378 1378
 
1379 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 1386
         scms_parent = XML.Element('scms')
1381 1387
         for scm in data.get('scm', []):
1382 1388
             self.registry.dispatch('scm', scms_parent, scm)

+ 2
- 0
setup.cfg View File

@@ -56,6 +56,8 @@ jenkins_jobs.projects =
56 56
     freestyle=jenkins_jobs.modules.project_freestyle:Freestyle
57 57
     matrix=jenkins_jobs.modules.project_matrix:Matrix
58 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 61
     multijob=jenkins_jobs.modules.project_multijob:MultiJob
60 62
     pipeline=jenkins_jobs.modules.project_pipeline:Pipeline
61 63
     workflow=jenkins_jobs.modules.project_workflow:Workflow

+ 5
- 0
tests/base.py View File

@@ -41,6 +41,7 @@ from jenkins_jobs.modules import project_externaljob
41 41
 from jenkins_jobs.modules import project_flow
42 42
 from jenkins_jobs.modules import project_matrix
43 43
 from jenkins_jobs.modules import project_maven
44
+from jenkins_jobs.modules import project_multibranch
44 45
 from jenkins_jobs.modules import project_multijob
45 46
 from jenkins_jobs.modules import view_list
46 47
 from jenkins_jobs.modules import view_pipeline
@@ -188,6 +189,10 @@ class BaseScenariosTestCase(testscenarios.TestWithScenarios, BaseTestCase):
188 189
                 project = project_flow.Flow(registry)
189 190
             elif (yaml_content['project-type'] == "multijob"):
190 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 196
             elif (yaml_content['project-type'] == "externaljob"):
192 197
                 project = project_externaljob.ExternalJob(registry)
193 198
 

+ 0
- 0
tests/multibranch/__init__.py View File


+ 84
- 0
tests/multibranch/fixtures/multi_scm_full.xml View File

@@ -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>

+ 21
- 0
tests/multibranch/fixtures/multi_scm_full.yaml View File

@@ -0,0 +1,21 @@
1
+name: 'demo-multibranch-multi-scm-full'
2
+description: 'Workflow demo'
3
+
4
+project-type: multibranch
5
+
6
+periodic-folder-trigger: 1d
7
+prune-dead-branches: True
8
+number-to-keep: '10'
9
+days-to-keep: '10'
10
+scm:
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'

+ 60
- 0
tests/multibranch/fixtures/multibranch_defaults.xml View File

@@ -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>

+ 7
- 0
tests/multibranch/fixtures/multibranch_defaults.yaml View File

@@ -0,0 +1,7 @@
1
+name: 'demo-multibranch-defaults'
2
+project-type: multibranch-defaults
3
+scm:
4
+    - github:
5
+        repo: 'foo'
6
+        repo-owner: 'johndoe'
7
+        credentials-id: 'secret'

+ 49
- 0
tests/multibranch/fixtures/scm_bitbucket_full.xml View File

@@ -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>

+ 7
- 0
tests/multibranch/fixtures/scm_bitbucket_full.yaml View File

@@ -0,0 +1,7 @@
1
+name: 'demo-multibranch-bitbucket-min'
2
+project-type: multibranch
3
+scm:
4
+    - bitbucket:
5
+        credentials-id: 'secret'
6
+        repo-owner: 'SANDBOX'
7
+        repo: 'test'

+ 48
- 0
tests/multibranch/fixtures/scm_bitbucket_minimal.xml View File

@@ -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>

+ 6
- 0
tests/multibranch/fixtures/scm_bitbucket_minimal.yaml View File

@@ -0,0 +1,6 @@
1
+name: 'demo-multibranch-bitbucket-min'
2
+project-type: multibranch
3
+scm:
4
+    - bitbucket:
5
+        repo-owner: 'SANDBOX'
6
+        repo: 'test'

+ 50
- 0
tests/multibranch/fixtures/scm_git_full.xml View File

@@ -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>

+ 8
- 0
tests/multibranch/fixtures/scm_git_full.yaml View File

@@ -0,0 +1,8 @@
1
+name: 'demo-multibranch-git-min'
2
+project-type: multibranch
3
+scm:
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

+ 50
- 0
tests/multibranch/fixtures/scm_git_minimal.xml View File

@@ -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>

+ 5
- 0
tests/multibranch/fixtures/scm_git_minimal.yaml View File

@@ -0,0 +1,5 @@
1
+name: 'demo-multibranch-git-min'
2
+project-type: multibranch
3
+scm:
4
+    - git:
5
+        url: 'https://example.com/jonhndoe/keep-frontend.git'

+ 61
- 0
tests/multibranch/fixtures/scm_github_full.xml View File

@@ -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>

+ 12
- 0
tests/multibranch/fixtures/scm_github_full.yaml View File

@@ -0,0 +1,12 @@
1
+name: scm-github-full
2
+project-type: multibranch
3
+scm:
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

+ 59
- 0
tests/multibranch/fixtures/scm_github_minimal.xml View File

@@ -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>

+ 6
- 0
tests/multibranch/fixtures/scm_github_minimal.yaml View File

@@ -0,0 +1,6 @@
1
+name: 'demo-multibranch-github-min'
2
+project-type: multibranch
3
+scm:
4
+    - github:
5
+        repo: 'foo'
6
+        repo-owner: 'johndoe'

+ 27
- 0
tests/multibranch/test_multibranch.py View File

@@ -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
+
16
+from tests import base
17
+import mock
18
+import os
19
+from jenkins_jobs.modules import project_multibranch
20
+
21
+
22
+@mock.patch('uuid.uuid4', mock.Mock(return_value='1-1-1-1-1'))
23
+class 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

Loading…
Cancel
Save