Merge "Added support of SCM Filter branch PR behavior filters for multibranch projects"
This commit is contained in:
commit
f80afac754
@ -374,6 +374,10 @@ def bitbucket_scm(xml_parent, data):
|
||||
:arg str head-filter-regex: A regular expression for filtering
|
||||
discovered source branches. Requires the :jenkins-plugins:`SCM API
|
||||
Plugin <scm-api>`.
|
||||
:arg list head-pr-filter-behaviors: Definition of Filter Branch PR behaviors.
|
||||
Requires the :jenkins-plugins:`SCM Filter Branch PR Plugin
|
||||
<scm-filter-branch-pr>`.
|
||||
Refer to :func:`~add_filter_branch_pr_behaviors <add_filter_branch_pr_behaviors>`.
|
||||
:arg str discover-branch: Discovers branches on the repository.
|
||||
Valid options: ex-pr, only-pr, all.
|
||||
Value is not specified by default.
|
||||
@ -522,6 +526,9 @@ def bitbucket_scm(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("head-pr-filter-behaviors", None):
|
||||
add_filter_branch_pr_behaviors(traits, data.get("head-pr-filter-behaviors"))
|
||||
|
||||
if data.get("discover-pr-origin", None):
|
||||
dpro = XML.SubElement(
|
||||
traits,
|
||||
@ -771,6 +778,10 @@ def git_scm(xml_parent, data):
|
||||
:arg str head-filter-regex: A regular expression for filtering
|
||||
discovered source branches. Requires the :jenkins-plugins:`SCM API
|
||||
Plugin <scm-api>`.
|
||||
:arg list head-pr-filter-behaviors: Definition of Filter Branch PR behaviors.
|
||||
Requires the :jenkins-plugins:`SCM Filter Branch PR Plugin
|
||||
<scm-filter-branch-pr>`.
|
||||
Refer to :func:`~add_filter_branch_pr_behaviors <add_filter_branch_pr_behaviors>`.
|
||||
: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
|
||||
@ -852,6 +863,9 @@ def git_scm(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("head-pr-filter-behaviors", None):
|
||||
add_filter_branch_pr_behaviors(traits, data.get("head-pr-filter-behaviors"))
|
||||
|
||||
if data.get("property-strategies", None):
|
||||
property_strategies(xml_parent, data)
|
||||
|
||||
@ -902,6 +916,10 @@ def github_scm(xml_parent, data):
|
||||
Valid options: merge-current, current, both, false. (default 'merge-current')
|
||||
:arg bool discover-tags: Discovers tags on the repository.
|
||||
(default false)
|
||||
:arg list head-pr-filter-behaviors: Definition of Filter Branch PR behaviors.
|
||||
Requires the :jenkins-plugins:`SCM Filter Branch PR Plugin
|
||||
<scm-filter-branch-pr>`.
|
||||
Refer to :func:`~add_filter_branch_pr_behaviors <add_filter_branch_pr_behaviors>`.
|
||||
: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
|
||||
@ -1060,6 +1078,9 @@ def github_scm(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("head-pr-filter-behaviors", None):
|
||||
add_filter_branch_pr_behaviors(traits, data.get("head-pr-filter-behaviors"))
|
||||
|
||||
if data.get("property-strategies", None):
|
||||
property_strategies(xml_parent, data)
|
||||
|
||||
@ -1620,3 +1641,113 @@ def apply_property_strategies(props_elem, props_list):
|
||||
"".join([pr_comment_build, pcb_bool_opts.get(opt)]),
|
||||
{"plugin": "github-pr-comment-build"},
|
||||
)
|
||||
|
||||
|
||||
def add_filter_branch_pr_behaviors(traits, data):
|
||||
"""Configure Filter Branch PR behaviors
|
||||
|
||||
Requires the :jenkins-plugins:`SCM Filter Branch PR Plugin
|
||||
<scm-filter-branch-pr>`.
|
||||
|
||||
:arg list head-pr-filter-behaviors: Definition of filters.
|
||||
|
||||
* **head-pr-destined-regex** (dict): Filter by name incl. PR destined to
|
||||
this branch with regexp
|
||||
|
||||
* **branch-regexp** (str) Regular expression to filter branches and
|
||||
PRs (optional, default ".*")
|
||||
* **tag-regexp** (str) Regular expression to filter tags
|
||||
(optional, default "(?!.*)")
|
||||
|
||||
* **head-pr-destined-wildcard** (dict): Filter by name incl. PR
|
||||
destined to this branch with wildcard
|
||||
|
||||
* **branch-includes** (str) Wildcard expression to include branches
|
||||
and PRs (optional, default "*")
|
||||
* **tag-includes** (str) Wildcard expression to include tags
|
||||
(optional, default "")
|
||||
* **branch-excludes** (str) Wildcard expression to exclude branches
|
||||
and PRs (optional, default "")
|
||||
* **tag-excludes** (str) Wildcard expression to exclude tags
|
||||
(optional, default "*")
|
||||
|
||||
* **head-pr-originated-regex** (dict): Filter by name incl. PR destined
|
||||
to this branch with regexp
|
||||
|
||||
* **branch-regexp** (str) Regular expression to filter branches
|
||||
and PRs (optional, default ".*")
|
||||
* **tag-regexp** (str) Regular expression to filter tags
|
||||
(optional, default "(?!.*)")
|
||||
|
||||
* **head-pr-originated-wildcard** (dict): Filter by name incl. PR
|
||||
destined to this branch with wildcard
|
||||
|
||||
* **branch-includes** (str) Wildcard expression to include branches
|
||||
and PRs (optional, default "*")
|
||||
* **tag-includes** (str) Wildcard expression to include tags
|
||||
(optional, default "")
|
||||
* **branch-excludes** (str) Wildcard expression to exclude branches
|
||||
and PRs (optional, default "")
|
||||
* **tag-excludes** (str) Wildcard expression to exclude tags
|
||||
(optional, default "*")
|
||||
"""
|
||||
|
||||
regexp_mapping = [
|
||||
("branch-regexp", "regex", ".*"),
|
||||
("tag-regexp", "tagRegex", "(?!.*)"),
|
||||
]
|
||||
wildcard_mapping = [
|
||||
("branch-includes", "includes", "*"),
|
||||
("branch-excludes", "excludes", ""),
|
||||
("tag-includes", "tagIncludes", ""),
|
||||
("tag-excludes", "tagExcludes", "*"),
|
||||
]
|
||||
|
||||
if data.get("head-pr-destined-regex"):
|
||||
rshf = XML.SubElement(
|
||||
traits,
|
||||
"net.gleske.scmfilter.impl.trait.RegexSCMHeadFilterTrait",
|
||||
{"plugin": "scm-filter-branch-pr"},
|
||||
)
|
||||
helpers.convert_mapping_to_xml(
|
||||
rshf, data.get("head-pr-destined-regex"), regexp_mapping, fail_required=True
|
||||
)
|
||||
|
||||
if data.get("head-pr-destined-wildcard"):
|
||||
wshf = XML.SubElement(
|
||||
traits,
|
||||
"net.gleske.scmfilter.impl.trait.WildcardSCMHeadFilterTrait",
|
||||
{"plugin": "scm-filter-branch-pr"},
|
||||
)
|
||||
helpers.convert_mapping_to_xml(
|
||||
wshf,
|
||||
data.get("head-pr-destined-wildcard"),
|
||||
wildcard_mapping,
|
||||
fail_required=True,
|
||||
)
|
||||
|
||||
if data.get("head-pr-originated-regex"):
|
||||
rsof = XML.SubElement(
|
||||
traits,
|
||||
"net.gleske.scmfilter.impl.trait.RegexSCMOriginFilterTrait",
|
||||
{"plugin": "scm-filter-branch-pr"},
|
||||
)
|
||||
helpers.convert_mapping_to_xml(
|
||||
rsof,
|
||||
data.get("head-pr-originated-regex"),
|
||||
regexp_mapping,
|
||||
fail_required=True,
|
||||
)
|
||||
|
||||
if data.get("head-pr-originated-wildcard"):
|
||||
wsof = XML.SubElement(
|
||||
traits,
|
||||
"net.gleske.scmfilter.impl.trait.WildcardSCMOriginFilterTrait",
|
||||
{"plugin": "scm-filter-branch-pr"},
|
||||
)
|
||||
helpers.convert_mapping_to_xml(
|
||||
wsof,
|
||||
data.get("head-pr-originated-wildcard"),
|
||||
wildcard_mapping,
|
||||
fail_required=True,
|
||||
)
|
||||
|
@ -55,6 +55,26 @@
|
||||
<jenkins.scm.impl.trait.RegexSCMHeadFilterTrait>
|
||||
<regex>master|\d+\.\d+</regex>
|
||||
</jenkins.scm.impl.trait.RegexSCMHeadFilterTrait>
|
||||
<net.gleske.scmfilter.impl.trait.RegexSCMHeadFilterTrait plugin="scm-filter-branch-pr">
|
||||
<regex>foo/.*</regex>
|
||||
<tagRegex>20\..*</tagRegex>
|
||||
</net.gleske.scmfilter.impl.trait.RegexSCMHeadFilterTrait>
|
||||
<net.gleske.scmfilter.impl.trait.WildcardSCMHeadFilterTrait plugin="scm-filter-branch-pr">
|
||||
<includes>foo*</includes>
|
||||
<excludes>bar*</excludes>
|
||||
<tagIncludes>qaz*</tagIncludes>
|
||||
<tagExcludes>*baz</tagExcludes>
|
||||
</net.gleske.scmfilter.impl.trait.WildcardSCMHeadFilterTrait>
|
||||
<net.gleske.scmfilter.impl.trait.RegexSCMOriginFilterTrait plugin="scm-filter-branch-pr">
|
||||
<regex>(foo/.*|bar/.*)</regex>
|
||||
<tagRegex>1\..*</tagRegex>
|
||||
</net.gleske.scmfilter.impl.trait.RegexSCMOriginFilterTrait>
|
||||
<net.gleske.scmfilter.impl.trait.WildcardSCMOriginFilterTrait plugin="scm-filter-branch-pr">
|
||||
<includes>qaz*</includes>
|
||||
<excludes>baz*</excludes>
|
||||
<tagIncludes>bar*</tagIncludes>
|
||||
<tagExcludes>*qaz</tagExcludes>
|
||||
</net.gleske.scmfilter.impl.trait.WildcardSCMOriginFilterTrait>
|
||||
<com.cloudbees.jenkins.plugins.bitbucket.OriginPullRequestDiscoveryTrait>
|
||||
<strategyId>2</strategyId>
|
||||
</com.cloudbees.jenkins.plugins.bitbucket.OriginPullRequestDiscoveryTrait>
|
||||
|
@ -10,6 +10,23 @@ scm:
|
||||
discover-tags: true
|
||||
lfs: true
|
||||
head-filter-regex: 'master|\d+\.\d+'
|
||||
head-pr-filter-behaviors:
|
||||
head-pr-destined-regex:
|
||||
branch-regexp: "foo/.*"
|
||||
tag-regexp: "20\\..*"
|
||||
head-pr-destined-wildcard:
|
||||
branch-includes: "foo*"
|
||||
tag-includes: "qaz*"
|
||||
branch-excludes: "bar*"
|
||||
tag-excludes: "*baz"
|
||||
head-pr-originated-regex:
|
||||
branch-regexp: "(foo/.*|bar/.*)"
|
||||
tag-regexp: "1\\..*"
|
||||
head-pr-originated-wildcard:
|
||||
branch-includes: "qaz*"
|
||||
tag-includes: "bar*"
|
||||
branch-excludes: "baz*"
|
||||
tag-excludes: "*qaz"
|
||||
discover-pr-origin: headOnly
|
||||
discover-branch: all
|
||||
discover-pr-forks-strategy: current
|
||||
|
@ -41,6 +41,26 @@
|
||||
<jenkins.scm.impl.trait.RegexSCMHeadFilterTrait>
|
||||
<regex>master|\d+\.\d+</regex>
|
||||
</jenkins.scm.impl.trait.RegexSCMHeadFilterTrait>
|
||||
<net.gleske.scmfilter.impl.trait.RegexSCMHeadFilterTrait plugin="scm-filter-branch-pr">
|
||||
<regex>foo/.*</regex>
|
||||
<tagRegex>20\..*</tagRegex>
|
||||
</net.gleske.scmfilter.impl.trait.RegexSCMHeadFilterTrait>
|
||||
<net.gleske.scmfilter.impl.trait.WildcardSCMHeadFilterTrait plugin="scm-filter-branch-pr">
|
||||
<includes>foo*</includes>
|
||||
<excludes>bar*</excludes>
|
||||
<tagIncludes>qaz*</tagIncludes>
|
||||
<tagExcludes>*baz</tagExcludes>
|
||||
</net.gleske.scmfilter.impl.trait.WildcardSCMHeadFilterTrait>
|
||||
<net.gleske.scmfilter.impl.trait.RegexSCMOriginFilterTrait plugin="scm-filter-branch-pr">
|
||||
<regex>(foo/.*|bar/.*)</regex>
|
||||
<tagRegex>1\..*</tagRegex>
|
||||
</net.gleske.scmfilter.impl.trait.RegexSCMOriginFilterTrait>
|
||||
<net.gleske.scmfilter.impl.trait.WildcardSCMOriginFilterTrait plugin="scm-filter-branch-pr">
|
||||
<includes>qaz*</includes>
|
||||
<excludes>baz*</excludes>
|
||||
<tagIncludes>bar*</tagIncludes>
|
||||
<tagExcludes>*qaz</tagExcludes>
|
||||
</net.gleske.scmfilter.impl.trait.WildcardSCMOriginFilterTrait>
|
||||
<jenkins.plugins.git.traits.CleanAfterCheckoutTrait>
|
||||
<extension class="hudson.plugins.git.extensions.impl.CleanCheckout"/>
|
||||
</jenkins.plugins.git.traits.CleanAfterCheckoutTrait>
|
||||
|
@ -9,6 +9,23 @@ scm:
|
||||
ignore-on-push-notifications: true
|
||||
discover-tags: true
|
||||
head-filter-regex: 'master|\d+\.\d+'
|
||||
head-pr-filter-behaviors:
|
||||
head-pr-destined-regex:
|
||||
branch-regexp: "foo/.*"
|
||||
tag-regexp: "20\\..*"
|
||||
head-pr-destined-wildcard:
|
||||
branch-includes: "foo*"
|
||||
tag-includes: "qaz*"
|
||||
branch-excludes: "bar*"
|
||||
tag-excludes: "*baz"
|
||||
head-pr-originated-regex:
|
||||
branch-regexp: "(foo/.*|bar/.*)"
|
||||
tag-regexp: "1\\..*"
|
||||
head-pr-originated-wildcard:
|
||||
branch-includes: "qaz*"
|
||||
tag-includes: "bar*"
|
||||
branch-excludes: "baz*"
|
||||
tag-excludes: "*qaz"
|
||||
property-strategies:
|
||||
all-branches:
|
||||
- suppress-scm-triggering: true
|
||||
|
@ -55,6 +55,26 @@
|
||||
<jenkins.scm.impl.trait.RegexSCMHeadFilterTrait>
|
||||
<regex>(.*/master|.*/release/.*)</regex>
|
||||
</jenkins.scm.impl.trait.RegexSCMHeadFilterTrait>
|
||||
<net.gleske.scmfilter.impl.trait.RegexSCMHeadFilterTrait plugin="scm-filter-branch-pr">
|
||||
<regex>foo/.*</regex>
|
||||
<tagRegex>20\..*</tagRegex>
|
||||
</net.gleske.scmfilter.impl.trait.RegexSCMHeadFilterTrait>
|
||||
<net.gleske.scmfilter.impl.trait.WildcardSCMHeadFilterTrait plugin="scm-filter-branch-pr">
|
||||
<includes>foo*</includes>
|
||||
<excludes>bar*</excludes>
|
||||
<tagIncludes>qaz*</tagIncludes>
|
||||
<tagExcludes>*baz</tagExcludes>
|
||||
</net.gleske.scmfilter.impl.trait.WildcardSCMHeadFilterTrait>
|
||||
<net.gleske.scmfilter.impl.trait.RegexSCMOriginFilterTrait plugin="scm-filter-branch-pr">
|
||||
<regex>(foo/.*|bar/.*)</regex>
|
||||
<tagRegex>1\..*</tagRegex>
|
||||
</net.gleske.scmfilter.impl.trait.RegexSCMOriginFilterTrait>
|
||||
<net.gleske.scmfilter.impl.trait.WildcardSCMOriginFilterTrait plugin="scm-filter-branch-pr">
|
||||
<includes>qaz*</includes>
|
||||
<excludes>baz*</excludes>
|
||||
<tagIncludes>bar*</tagIncludes>
|
||||
<tagExcludes>*qaz</tagExcludes>
|
||||
</net.gleske.scmfilter.impl.trait.WildcardSCMOriginFilterTrait>
|
||||
<org.jenkinsci.plugins.githubScmTraitNotificationContext.NotificationContextTrait>
|
||||
<contextLabel>jenkins.example.com/my_context</contextLabel>
|
||||
<typeSuffix>true</typeSuffix>
|
||||
|
@ -11,6 +11,23 @@ scm:
|
||||
credentials-id: example-credential
|
||||
branch-discovery: all
|
||||
head-filter-regex: "(.*/master|.*/release/.*)"
|
||||
head-pr-filter-behaviors:
|
||||
head-pr-destined-regex:
|
||||
branch-regexp: "foo/.*"
|
||||
tag-regexp: "20\\..*"
|
||||
head-pr-destined-wildcard:
|
||||
branch-includes: "foo*"
|
||||
tag-includes: "qaz*"
|
||||
branch-excludes: "bar*"
|
||||
tag-excludes: "*baz"
|
||||
head-pr-originated-regex:
|
||||
branch-regexp: "(foo/.*|bar/.*)"
|
||||
tag-regexp: "1\\..*"
|
||||
head-pr-originated-wildcard:
|
||||
branch-includes: "qaz*"
|
||||
tag-includes: "bar*"
|
||||
branch-excludes: "baz*"
|
||||
tag-excludes: "*qaz"
|
||||
discover-pr-forks-strategy: both
|
||||
discover-pr-forks-trust: everyone
|
||||
discover-pr-origin: both
|
||||
|
Loading…
Reference in New Issue
Block a user