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>
This commit is contained in:
amit lin 2019-01-07 16:47:25 +02:00
parent b1499530db
commit ff338dc948
3 changed files with 9 additions and 0 deletions

View File

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

View File

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

View File

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