Browse Source

Adds github scm multibranch regex branch filter

This commit adds the ability to filter discovered branches in a multibranch project using a regex filter.
This is done by adding a 'head-filter-regex' key in the github scm configuration inside the multibranch job yaml - it maps to a <jenkins.scm.impl.trait.RegexSCMHeadFilterTrait>
element containing a <regex> element in the resulting job.

Change-Id: I8c88a8b131cdc51d2c8abb13397637ebbf6d1373
Signed-off-by: amit lin <amitl@totango.com>
tags/2.10.0
amit lin 4 months ago
parent
commit
ff338dc948

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

@@ -968,6 +968,11 @@ def github_scm(xml_parent, data):
968 968
     helpers.convert_mapping_to_xml(
969 969
         dpro, data, dpro_mapping, fail_required=True)
970 970
 
971
+    if data.get('head-filter-regex', None):
972
+        rshf = XML.SubElement(traits,
973
+            'jenkins.scm.impl.trait.RegexSCMHeadFilterTrait')
974
+        XML.SubElement(rshf, 'regex').text = data.get('head-filter-regex')
975
+
971 976
     if data.get('property-strategies', None):
972 977
         property_strategies(xml_parent, data)
973 978
 

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

@@ -52,6 +52,9 @@
52 52
             <org.jenkinsci.plugins.github__branch__source.OriginPullRequestDiscoveryTrait>
53 53
               <strategyId>3</strategyId>
54 54
             </org.jenkinsci.plugins.github__branch__source.OriginPullRequestDiscoveryTrait>
55
+            <jenkins.scm.impl.trait.RegexSCMHeadFilterTrait>
56
+              <regex>(.*/master|.*/release/.*)</regex>
57
+            </jenkins.scm.impl.trait.RegexSCMHeadFilterTrait>
55 58
             <jenkins.plugins.git.traits.CleanAfterCheckoutTrait>
56 59
               <extension class="hudson.plugins.git.extensions.impl.CleanCheckout"/>
57 60
             </jenkins.plugins.git.traits.CleanAfterCheckoutTrait>

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

@@ -10,6 +10,7 @@ scm:
10 10
         repo-owner: example-owner
11 11
         credentials-id: example-credential
12 12
         branch-discovery: all
13
+        head-filter-regex: "(.*/master|.*/release/.*)"
13 14
         discover-pr-forks-strategy: both
14 15
         discover-pr-forks-trust: everyone
15 16
         discover-pr-origin: both

Loading…
Cancel
Save