From ff338dc948d5fec0ba7c3ced1f3630e00890b426 Mon Sep 17 00:00:00 2001 From: amit lin Date: Mon, 7 Jan 2019 16:47:25 +0200 Subject: [PATCH] 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 element containing a element in the resulting job. Change-Id: I8c88a8b131cdc51d2c8abb13397637ebbf6d1373 Signed-off-by: amit lin --- jenkins_jobs/modules/project_multibranch.py | 5 +++++ tests/multibranch/fixtures/scm_github_full.xml | 3 +++ tests/multibranch/fixtures/scm_github_full.yaml | 1 + 3 files changed, 9 insertions(+) diff --git a/jenkins_jobs/modules/project_multibranch.py b/jenkins_jobs/modules/project_multibranch.py index 1c331b091..eec044116 100644 --- a/jenkins_jobs/modules/project_multibranch.py +++ b/jenkins_jobs/modules/project_multibranch.py @@ -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) diff --git a/tests/multibranch/fixtures/scm_github_full.xml b/tests/multibranch/fixtures/scm_github_full.xml index a74e2e6d4..cc4efcc10 100644 --- a/tests/multibranch/fixtures/scm_github_full.xml +++ b/tests/multibranch/fixtures/scm_github_full.xml @@ -52,6 +52,9 @@ 3 + + (.*/master|.*/release/.*) + diff --git a/tests/multibranch/fixtures/scm_github_full.yaml b/tests/multibranch/fixtures/scm_github_full.yaml index 9b74e8377..a45ecb65e 100644 --- a/tests/multibranch/fixtures/scm_github_full.yaml +++ b/tests/multibranch/fixtures/scm_github_full.yaml @@ -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