diff --git a/jenkins_jobs/modules/project_multibranch.py b/jenkins_jobs/modules/project_multibranch.py index ac85974fb..8283cd5d8 100644 --- a/jenkins_jobs/modules/project_multibranch.py +++ b/jenkins_jobs/modules/project_multibranch.py @@ -653,6 +653,9 @@ def gerrit_scm(xml_parent, data): (default '*') :arg str excludes: Comma-separated list of branches to be excluded. (default '') + :arg str head-filter-regex: A regular expression for filtering + discovered source branches. Requires the :jenkins-plugins:`SCM API + Plugin `. :arg list build-strategies: Provides control over whether to build a branch (or branch like things such as change requests and tags) whenever it is discovered initially or a change from the previous revision has been @@ -786,6 +789,10 @@ def gerrit_scm(xml_parent, data): if data.get("build-strategies", None): build_strategies(xml_parent, data) + 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") + # FilterChecks Trait checks = data.get("filter-checks", None) if checks: diff --git a/tests/multibranch/fixtures/scm_gerrit_full.xml b/tests/multibranch/fixtures/scm_gerrit_full.xml index d7f30ba1f..c161004ea 100644 --- a/tests/multibranch/fixtures/scm_gerrit_full.xml +++ b/tests/multibranch/fixtures/scm_gerrit_full.xml @@ -47,6 +47,9 @@ + + (.*/master|.*/release/.*) + SCHEME jenkins diff --git a/tests/multibranch/fixtures/scm_gerrit_full.yaml b/tests/multibranch/fixtures/scm_gerrit_full.yaml index 34e8d5fae..e35f9be5a 100644 --- a/tests/multibranch/fixtures/scm_gerrit_full.yaml +++ b/tests/multibranch/fixtures/scm_gerrit_full.yaml @@ -46,6 +46,7 @@ scm: - exact-name: {} - regex-name: {} - wildcards-name: {} + head-filter-regex: "(.*/master|.*/release/.*)" clean: after: true before: true