Browse Source

Add discover-tags to multibranch pipeline project

Add the option to specify discover-tags on bitbucket, git and
github SCMs in multibranch pipeline.

Change-Id: I28a4bc3a4bb5d50b8d7717b19ef063a23a68ed8c
Task: 20061
Story: 2002187
tags/2.0.10
Konrad Beiske 11 months ago
parent
commit
af6b031d09

+ 21
- 1
jenkins_jobs/modules/project_multibranch.py View File

@@ -296,6 +296,9 @@ def bitbucket_scm(xml_parent, data):
296 296
         User Account. (required)
297 297
     :arg str repo: The BitBucket repo. (required)
298 298
 
299
+    :arg bool discover-tags: Discovers tags on the repository.
300
+        (default false)
301
+
299 302
     Minimal Example:
300 303
 
301 304
     .. literalinclude::
@@ -324,7 +327,10 @@ def bitbucket_scm(xml_parent, data):
324 327
     helpers.convert_mapping_to_xml(
325 328
         source, data, mapping_optional, fail_required=False)
326 329
 
327
-    XML.SubElement(source, 'traits')
330
+    traits = XML.SubElement(source, 'traits')
331
+    if data.get('discover-tags', False):
332
+        XML.SubElement(traits,
333
+            'com.cloudbees.jenkins.plugins.bitbucket.TagDiscoveryTrait')
328 334
 
329 335
 
330 336
 def gerrit_scm(xml_parent, data):
@@ -413,6 +419,8 @@ def git_scm(xml_parent, data):
413 419
 
414 420
     :arg bool discover-branches: Discovers branches on the repository.
415 421
         (default true)
422
+    :arg bool discover-tags: Discovers tags on the repository.
423
+        (default false)
416 424
     :arg bool ignore-on-push-notifications: If a job should not trigger upon
417 425
         push notifications. (default false)
418 426
 
@@ -446,6 +454,9 @@ def git_scm(xml_parent, data):
446 454
     if data.get('discover-branches', True):
447 455
         XML.SubElement(traits, ''.join([traits_path, '.BranchDiscoveryTrait']))
448 456
 
457
+    if data.get('discover-tags', False):
458
+        XML.SubElement(traits, ''.join([traits_path, '.TagDiscoveryTrait']))
459
+
449 460
     if data.get('ignore-on-push-notifications', False):
450 461
         XML.SubElement(
451 462
             traits, ''.join([traits_path, '.IgnoreOnPushNotificationTrait']))
@@ -476,6 +487,8 @@ def github_scm(xml_parent, data):
476 487
     :arg str discover-pr-origin: Discovers pull requests where the origin
477 488
         repository is the same as the target repository.
478 489
         Valid options: merge-current, current, both.  (default 'merge-current')
490
+    :arg bool discover-tags: Discovers tags on the repository.
491
+        (default false)
479 492
 
480 493
     Minimal Example:
481 494
 
@@ -526,6 +539,13 @@ def github_scm(xml_parent, data):
526 539
         helpers.convert_mapping_to_xml(
527 540
             bd, data, bd_mapping, fail_required=True)
528 541
 
542
+    if data.get('discover-tags', False):
543
+        XML.SubElement(
544
+            traits, ''.join([
545
+                github_path_dscore, '.TagDiscoveryTrait'
546
+            ])
547
+        )
548
+
529 549
     if data.get('discover-pr-forks-strategy', 'merged-current'):
530 550
         dprf = XML.SubElement(
531 551
             traits, ''.join([

+ 3
- 1
tests/multibranch/fixtures/scm_bitbucket_full.xml View File

@@ -36,7 +36,9 @@
36 36
           <repoOwner>SANDBOX</repoOwner>
37 37
           <repository>test</repository>
38 38
           <credentialsId>secret</credentialsId>
39
-          <traits/>
39
+          <traits>
40
+            <com.cloudbees.jenkins.plugins.bitbucket.TagDiscoveryTrait/>
41
+          </traits>
40 42
         </source>
41 43
       </jenkins.branch.BranchSource>
42 44
     </data>

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

@@ -5,3 +5,4 @@ scm:
5 5
         credentials-id: 'secret'
6 6
         repo-owner: 'SANDBOX'
7 7
         repo: 'test'
8
+        discover-tags: true

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

@@ -36,6 +36,7 @@
36 36
           <remote>https://example.com/jonhndoe/keep-frontend.git</remote>
37 37
           <credentialsId>secret</credentialsId>
38 38
           <traits>
39
+            <jenkins.plugins.git.traits.TagDiscoveryTrait/>
39 40
             <jenkins.plugins.git.traits.IgnoreOnPushNotificationTrait/>
40 41
           </traits>
41 42
         </source>

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

@@ -6,3 +6,4 @@ scm:
6 6
         credentials-id: secret
7 7
         discover-branches: false
8 8
         ignore-on-push-notifications: true
9
+        discover-tags: true

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

@@ -41,6 +41,7 @@
41 41
             <org.jenkinsci.plugins.github__branch__source.BranchDiscoveryTrait>
42 42
               <strategyId>3</strategyId>
43 43
             </org.jenkinsci.plugins.github__branch__source.BranchDiscoveryTrait>
44
+            <org.jenkinsci.plugins.github__branch__source.TagDiscoveryTrait/>
44 45
             <org.jenkinsci.plugins.github__branch__source.ForkPullRequestDiscoveryTrait>
45 46
               <strategyId>3</strategyId>
46 47
               <trust class="org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait$TrustEveryone"/>

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

@@ -10,3 +10,4 @@ scm:
10 10
         discover-pr-forks-strategy: both
11 11
         discover-pr-forks-trust: everyone
12 12
         discover-pr-origin: both
13
+        discover-tags: true

Loading…
Cancel
Save