diff --git a/jenkins_jobs/modules/project_multibranch.py b/jenkins_jobs/modules/project_multibranch.py index a30ef5bc6..2b803712c 100644 --- a/jenkins_jobs/modules/project_multibranch.py +++ b/jenkins_jobs/modules/project_multibranch.py @@ -621,22 +621,7 @@ def bitbucket_scm(xml_parent, data): cossh, data.get("checkout-over-ssh"), cossh_credentials, fail_required=True ) - if data.get("filter-by-name-wildcard", None): - wscmf_name = XML.SubElement( - traits, - "jenkins.scm.impl.trait.WildcardSCMHeadFilterTrait", - {"plugin": "scm-api"}, - ) - wscmf_name_mapping = [ - ("includes", "includes", ""), - ("excludes", "excludes", ""), - ] - helpers.convert_mapping_to_xml( - wscmf_name, - data.get("filter-by-name-wildcard", ""), - wscmf_name_mapping, - fail_required=True, - ) + add_filter_by_name_wildcard_behaviors(traits, data) # handle the default git extensions like: # - clean @@ -943,6 +928,15 @@ def github_scm(xml_parent, data): (like to disable SCM triggering or to override the pipeline durability) (optional) Refer to :func:`~property_strategies `. + :arg dict filter-by-name-wildcard: Enable filter by name with wildcards. + Requires the :jenkins-plugins:`SCM API Plugin `. + + * **includes** ('str'): Space-separated list + of name patterns to consider. You may use * as a wildcard; + for example: `master release*` + * **excludes** ('str'): Name patterns to + ignore even if matched by the includes list. + For example: `release*` :extensions: @@ -1110,6 +1104,8 @@ def github_scm(xml_parent, data): XML.SubElement(rshf, "contextLabel").text = data.get("notification-context") XML.SubElement(rshf, "typeSuffix").text = "true" + add_filter_by_name_wildcard_behaviors(traits, data) + # handle the default git extensions like: # - clean # - shallow-clone @@ -1766,3 +1762,34 @@ def add_filter_branch_pr_behaviors(traits, data): wildcard_mapping, fail_required=True, ) + + +def add_filter_by_name_wildcard_behaviors(traits, data): + """Configure branch filtering behaviors. + + :arg dict filter-by-name-wildcard: Enable filter by name with wildcards. + Requires the :jenkins-plugins:`SCM API Plugin `. + + * **includes** ('str'): Space-separated list + of name patterns to consider. You may use * as a wildcard; + for example: `master release*` + * **excludes** ('str'): Name patterns to + ignore even if matched by the includes list. + For example: `release*` + """ + if data.get("filter-by-name-wildcard", None): + wscmf_name = XML.SubElement( + traits, + "jenkins.scm.impl.trait.WildcardSCMHeadFilterTrait", + {"plugin": "scm-api"}, + ) + wscmf_name_mapping = [ + ("includes", "includes", ""), + ("excludes", "excludes", ""), + ] + helpers.convert_mapping_to_xml( + wscmf_name, + data.get("filter-by-name-wildcard", ""), + wscmf_name_mapping, + fail_required=True, + ) diff --git a/tests/multibranch/fixtures/scm_github_filter_by_name_wildcard.xml b/tests/multibranch/fixtures/scm_github_filter_by_name_wildcard.xml new file mode 100644 index 000000000..ddab5699d --- /dev/null +++ b/tests/multibranch/fixtures/scm_github_filter_by_name_wildcard.xml @@ -0,0 +1,66 @@ + + + + + + All + false + false + + + + + + + + + + + false + + + + + + + true + -1 + -1 + + + + + + + gh-johndoe-foo + johndoe + foo + + + 1 + + + 1 + + + + 1 + + + includes-branch-* + excludes-branch-* + + + + + + + + + + + + + Jenkinsfile + + diff --git a/tests/multibranch/fixtures/scm_github_filter_by_name_wildcard.yaml b/tests/multibranch/fixtures/scm_github_filter_by_name_wildcard.yaml new file mode 100644 index 000000000..162f5b612 --- /dev/null +++ b/tests/multibranch/fixtures/scm_github_filter_by_name_wildcard.yaml @@ -0,0 +1,10 @@ +name: 'demo-multibranch-github-min' +project-type: multibranch +scm: + - github: + repo: 'foo' + repo-owner: 'johndoe' + + filter-by-name-wildcard: + includes: includes-branch-* + excludes: excludes-branch-*