summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoramit lin <amitl@totango.com>2019-01-07 16:47:25 +0200
committeramit lin <amitl@totango.com>2019-01-07 18:12:29 +0200
commitff338dc948d5fec0ba7c3ced1f3630e00890b426 (patch)
tree0d416c8c1aeab0a84970f059bb0d4a1d639ae29e
parentb1499530dbb5ad66f52fbfc4ffa1343da79df441 (diff)
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>
Notes
Notes (review): Code-Review+2: Thanh Ha (zxiiro) <zxiiro@gmail.com> Code-Review+2: Sorin Sbarnea <ssbarnea@redhat.com> Workflow+1: Sorin Sbarnea <ssbarnea@redhat.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Tue, 08 Jan 2019 16:15:27 +0000 Reviewed-on: https://review.openstack.org/628987 Project: openstack-infra/jenkins-job-builder Branch: refs/heads/master
-rw-r--r--jenkins_jobs/modules/project_multibranch.py5
-rw-r--r--tests/multibranch/fixtures/scm_github_full.xml3
-rw-r--r--tests/multibranch/fixtures/scm_github_full.yaml1
3 files changed, 9 insertions, 0 deletions
diff --git a/jenkins_jobs/modules/project_multibranch.py b/jenkins_jobs/modules/project_multibranch.py
index 1c331b0..eec0441 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):
968 helpers.convert_mapping_to_xml( 968 helpers.convert_mapping_to_xml(
969 dpro, data, dpro_mapping, fail_required=True) 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 if data.get('property-strategies', None): 976 if data.get('property-strategies', None):
972 property_strategies(xml_parent, data) 977 property_strategies(xml_parent, data)
973 978
diff --git a/tests/multibranch/fixtures/scm_github_full.xml b/tests/multibranch/fixtures/scm_github_full.xml
index a74e2e6..cc4efcc 100644
--- a/tests/multibranch/fixtures/scm_github_full.xml
+++ b/tests/multibranch/fixtures/scm_github_full.xml
@@ -52,6 +52,9 @@
52 <org.jenkinsci.plugins.github__branch__source.OriginPullRequestDiscoveryTrait> 52 <org.jenkinsci.plugins.github__branch__source.OriginPullRequestDiscoveryTrait>
53 <strategyId>3</strategyId> 53 <strategyId>3</strategyId>
54 </org.jenkinsci.plugins.github__branch__source.OriginPullRequestDiscoveryTrait> 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 <jenkins.plugins.git.traits.CleanAfterCheckoutTrait> 58 <jenkins.plugins.git.traits.CleanAfterCheckoutTrait>
56 <extension class="hudson.plugins.git.extensions.impl.CleanCheckout"/> 59 <extension class="hudson.plugins.git.extensions.impl.CleanCheckout"/>
57 </jenkins.plugins.git.traits.CleanAfterCheckoutTrait> 60 </jenkins.plugins.git.traits.CleanAfterCheckoutTrait>
diff --git a/tests/multibranch/fixtures/scm_github_full.yaml b/tests/multibranch/fixtures/scm_github_full.yaml
index 9b74e83..a45ecb6 100644
--- a/tests/multibranch/fixtures/scm_github_full.yaml
+++ b/tests/multibranch/fixtures/scm_github_full.yaml
@@ -10,6 +10,7 @@ scm:
10 repo-owner: example-owner 10 repo-owner: example-owner
11 credentials-id: example-credential 11 credentials-id: example-credential
12 branch-discovery: all 12 branch-discovery: all
13 head-filter-regex: "(.*/master|.*/release/.*)"
13 discover-pr-forks-strategy: both 14 discover-pr-forks-strategy: both
14 discover-pr-forks-trust: everyone 15 discover-pr-forks-trust: everyone
15 discover-pr-origin: both 16 discover-pr-origin: both