diff --git a/jenkins_jobs/modules/project_githuborg.py b/jenkins_jobs/modules/project_githuborg.py index 75a8fa6b7..fb8f2fa14 100644 --- a/jenkins_jobs/modules/project_githuborg.py +++ b/jenkins_jobs/modules/project_githuborg.py @@ -206,6 +206,9 @@ def github_org(xml_parent, data): first be configured in Global Configuration. (default GitHub) :arg str branch-discovery: Discovers branches on the repository. Valid options: no-pr, only-pr, all, false. (default 'no-pr') + :arg str repo-name-regex: Regular expression used to match repository names + within the organization. (optional) + 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 @@ -384,6 +387,14 @@ def github_org(xml_parent, data): rshf = XML.SubElement(traits, "jenkins.scm.impl.trait.RegexSCMHeadFilterTrait") XML.SubElement(rshf, "regex").text = data.get("head-filter-regex") + if data.get("repo-name-regex", None): + rssf = XML.SubElement( + traits, + "jenkins.scm.impl.trait.RegexSCMSourceFilterTrait", + {"plugin": "scm-api"}, + ) + XML.SubElement(rssf, "regex").text = data.get("repo-name-regex") + if data.get("head-pr-filter-behaviors", None): multibranch.add_filter_branch_pr_behaviors( traits, data.get("head-pr-filter-behaviors") diff --git a/tests/githuborg/fixtures/github-org-full.xml b/tests/githuborg/fixtures/github-org-full.xml index c4b1c26a4..72194a96f 100644 --- a/tests/githuborg/fixtures/github-org-full.xml +++ b/tests/githuborg/fixtures/github-org-full.xml @@ -41,6 +41,9 @@ (.*/master|.*/release/.*) + + example-repo-name|fancy-regex* + foo/.* 20\..* diff --git a/tests/githuborg/fixtures/github-org-full.yaml b/tests/githuborg/fixtures/github-org-full.yaml index cf3cb6c85..3525e6301 100644 --- a/tests/githuborg/fixtures/github-org-full.yaml +++ b/tests/githuborg/fixtures/github-org-full.yaml @@ -7,6 +7,7 @@ github-org: repo-owner: example-owner credentials-id: example-credential branch-discovery: all + repo-name-regex: "example-repo-name|fancy-regex*" head-filter-regex: "(.*/master|.*/release/.*)" head-pr-filter-behaviors: head-pr-destined-regex: