Added configuration for Suppress SCM Triggering
In version 2.1045.v4ec3ed07b_e4f Branch API Plugin added options to configure suppressing SCM trigger. Previously this feature could be only turned on or off, now it's possible to select what to suppress and on which branches. (see https://github.com/jenkinsci/branch-api-plugin/pull/244) This commit adds support for this option by allowing dictionary syntax for `suppress-scm-triggering` element: ``` - suppress-scm-triggering: suppression-strategy: suppress-branch-indexing branch-regex: ^.*test.*$ ``` while preserving support for currently existing syntax: ``` - suppress-scm-triggering: true ``` Change-Id: I5d0b32042fc07d674bf2f26e5b468f051077fb02
This commit is contained in:
parent
9ecd7fc92d
commit
cd8c8bfbb7
@ -1460,8 +1460,21 @@ def property_strategies(xml_parent, data):
|
||||
* **all-branches** (list): A list of property strategy definitions
|
||||
for use with all branches.
|
||||
|
||||
* **suppress-scm-triggering** (bool): Suppresses automatic SCM
|
||||
triggering (optional)
|
||||
* **suppress-scm-triggering** (dict):
|
||||
Suppresses automatic SCM triggering (optional).
|
||||
|
||||
* **branch-regex** (str):
|
||||
Regex matching branch names.
|
||||
Only these branches will be affected by the selected
|
||||
suppression strategy. Default ``^$``.
|
||||
* **suppress-strategy** (str):
|
||||
Select what to suppress for branches matching the regex.
|
||||
Valid values: ``suppress-nothing`` (default),
|
||||
``suppress-branch-indexing``, or ``suppress-webhooks``.
|
||||
|
||||
.. note::
|
||||
Using ``suppress-scm-triggering: true`` is deprecated
|
||||
since Branch API 2.1045.v4ec3ed07b_e4f.
|
||||
* **pipeline-branch-durability-override** (str): Set a custom
|
||||
branch speed/durability level. Valid values:
|
||||
performance-optimized, survivable-nonatomic, or
|
||||
@ -1509,8 +1522,21 @@ def property_strategies(xml_parent, data):
|
||||
to be applied by default to all branches, unless overridden
|
||||
by an entry in `exceptions`
|
||||
|
||||
* **suppress-scm-triggering** (bool): Suppresses automatic SCM
|
||||
triggering (optional)
|
||||
* **suppress-scm-triggering** (dict):
|
||||
Suppresses automatic SCM triggering (optional).
|
||||
|
||||
* **branch-regex** (str):
|
||||
Regex matching branch names.
|
||||
Only these branches will be affected by the selected
|
||||
suppression strategy. Default ``^$``.
|
||||
* **suppress-strategy** (str):
|
||||
Select what to suppress for branches matching the regex.
|
||||
Valid values: ``suppress-nothing`` (default),
|
||||
``suppress-branch-indexing``, or ``suppress-webhooks``.
|
||||
|
||||
.. note::
|
||||
Using ``suppress-scm-triggering: true`` is deprecated
|
||||
since Branch API 2.1045.v4ec3ed07b_e4f.
|
||||
* **pipeline-branch-durability-override** (str): Set a custom
|
||||
branch speed/durability level. Valid values:
|
||||
performance-optimized, survivable-nonatomic, or
|
||||
@ -1562,8 +1588,22 @@ def property_strategies(xml_parent, data):
|
||||
* **properties** (list): A list of properties to apply to
|
||||
this branch.
|
||||
|
||||
* **suppress-scm-triggering** (bool): Suppresses
|
||||
automatic SCM triggering (optional)
|
||||
* **suppress-scm-triggering** (dict):
|
||||
Suppresses automatic SCM triggering (optional).
|
||||
|
||||
* **branch-regex** (str):
|
||||
Regex matching branch names.
|
||||
Only these branches will be affected by the selected
|
||||
suppression strategy. Default ``^$``.
|
||||
* **suppress-strategy** (str):
|
||||
Select what to suppress for branches matching the regex.
|
||||
Valid values: ``suppress-nothing`` (default),
|
||||
``suppress-branch-indexing``, or ``suppress-webhooks``.
|
||||
|
||||
.. note::
|
||||
Using ``suppress-scm-triggering: true`` is deprecated
|
||||
since Branch API 2.1045.v4ec3ed07b_e4f.
|
||||
|
||||
* **pipeline-branch-durability-override** (str): Set a
|
||||
custom branch speed/durability level. Valid values:
|
||||
performance-optimized, survivable-nonatomic, or
|
||||
@ -1733,14 +1773,49 @@ def apply_property_strategies(props_elem, props_list):
|
||||
]
|
||||
)
|
||||
|
||||
# valid options for suppress SCM trigger property
|
||||
# strategy name says what's blocked
|
||||
sst_map = collections.OrderedDict(
|
||||
[
|
||||
("suppress-nothing", "NONE"),
|
||||
("suppress-webhooks", "EVENTS"),
|
||||
("suppress-branch-indexing", "INDEXING"),
|
||||
]
|
||||
)
|
||||
|
||||
for dbs_list in props_list:
|
||||
|
||||
if dbs_list.get("suppress-scm-triggering", False):
|
||||
XML.SubElement(
|
||||
sst_val = dbs_list.get("suppress-scm-triggering", False)
|
||||
if sst_val:
|
||||
sst_elem = XML.SubElement(
|
||||
props_elem,
|
||||
"".join([basic_property_strategies, ".NoTriggerBranchProperty"]),
|
||||
)
|
||||
|
||||
if isinstance(sst_val, dict):
|
||||
if "branch-regex" not in sst_val:
|
||||
raise MissingAttributeError("suppress-scm-triggering[branch-regex]")
|
||||
if "suppression-strategy" not in sst_val:
|
||||
raise MissingAttributeError(
|
||||
"suppress-scm-triggering[suppression-strategy]"
|
||||
)
|
||||
|
||||
sst_ss_val = sst_val["suppression-strategy"]
|
||||
if not sst_map.get(sst_ss_val):
|
||||
raise InvalidAttributeError(
|
||||
"suppression-strategy", sst_ss_val, sst_map.keys()
|
||||
)
|
||||
XML.SubElement(sst_elem, "triggeredBranchesRegex").text = sst_val[
|
||||
"branch-regex"
|
||||
]
|
||||
XML.SubElement(sst_elem, "strategy").text = sst_map[sst_ss_val]
|
||||
|
||||
elif isinstance(sst_val, bool):
|
||||
# no sub-elements in this case
|
||||
pass
|
||||
else:
|
||||
raise InvalidAttributeError("suppress-scm-triggering", sst_val)
|
||||
|
||||
pbdo_val = dbs_list.get("pipeline-branch-durability-override", None)
|
||||
if pbdo_val:
|
||||
if not pbdo_map.get(pbdo_val):
|
||||
|
@ -0,0 +1 @@
|
||||
'['test']' is an invalid value for attribute name.suppress-scm-triggering
|
@ -0,0 +1,17 @@
|
||||
name: 'demo-multibranch-github-min'
|
||||
project-type: multibranch
|
||||
scm:
|
||||
- github:
|
||||
repo: 'foo'
|
||||
repo-owner: 'johndoe'
|
||||
|
||||
property-strategies:
|
||||
all-branches:
|
||||
- suppress-scm-triggering:
|
||||
- test
|
||||
- pipeline-branch-durability-override: max-survivability
|
||||
- trigger-build-on-pr-comment: "Ci build!"
|
||||
- trigger-build-on-pr-review:
|
||||
allow-untrusted-users: false
|
||||
- trigger-build-on-pr-update:
|
||||
allow-untrusted-users: false
|
@ -0,0 +1 @@
|
||||
Missing suppress-scm-triggering[branch-regex] from an instance of 'name'
|
@ -0,0 +1,17 @@
|
||||
name: 'demo-multibranch-github-min'
|
||||
project-type: multibranch
|
||||
scm:
|
||||
- github:
|
||||
repo: 'foo'
|
||||
repo-owner: 'johndoe'
|
||||
|
||||
property-strategies:
|
||||
all-branches:
|
||||
- suppress-scm-triggering:
|
||||
suppression-strategy: suppress-webhooks
|
||||
- pipeline-branch-durability-override: max-survivability
|
||||
- trigger-build-on-pr-comment: "Ci build!"
|
||||
- trigger-build-on-pr-review:
|
||||
allow-untrusted-users: false
|
||||
- trigger-build-on-pr-update:
|
||||
allow-untrusted-users: false
|
@ -0,0 +1 @@
|
||||
Missing suppress-scm-triggering[suppression-strategy] from an instance of 'name'
|
@ -0,0 +1,17 @@
|
||||
name: 'demo-multibranch-github-min'
|
||||
project-type: multibranch
|
||||
scm:
|
||||
- github:
|
||||
repo: 'foo'
|
||||
repo-owner: 'johndoe'
|
||||
|
||||
property-strategies:
|
||||
all-branches:
|
||||
- suppress-scm-triggering:
|
||||
branch-regex: ^.*test.*$
|
||||
- pipeline-branch-durability-override: max-survivability
|
||||
- trigger-build-on-pr-comment: "Ci build!"
|
||||
- trigger-build-on-pr-review:
|
||||
allow-untrusted-users: false
|
||||
- trigger-build-on-pr-update:
|
||||
allow-untrusted-users: false
|
@ -0,0 +1,2 @@
|
||||
'suppress-build' is an invalid value for attribute name.suppression-strategy
|
||||
Valid values include: 'suppress-nothing', 'suppress-webhooks', 'suppress-branch-indexing'
|
@ -0,0 +1,18 @@
|
||||
name: 'demo-multibranch-github-min'
|
||||
project-type: multibranch
|
||||
scm:
|
||||
- github:
|
||||
repo: 'foo'
|
||||
repo-owner: 'johndoe'
|
||||
|
||||
property-strategies:
|
||||
all-branches:
|
||||
- suppress-scm-triggering:
|
||||
suppression-strategy: suppress-build
|
||||
branch-regex: ^$
|
||||
- pipeline-branch-durability-override: max-survivability
|
||||
- trigger-build-on-pr-comment: "Ci build!"
|
||||
- trigger-build-on-pr-review:
|
||||
allow-untrusted-users: false
|
||||
- trigger-build-on-pr-update:
|
||||
allow-untrusted-users: false
|
@ -167,7 +167,10 @@
|
||||
<strategy class="jenkins.branch.DefaultBranchPropertyStrategy">
|
||||
<properties class="java.util.Arrays$ArrayList">
|
||||
<a class="jenkins.branch.BranchProperty-array">
|
||||
<jenkins.branch.NoTriggerBranchProperty/>
|
||||
<jenkins.branch.NoTriggerBranchProperty>
|
||||
<triggeredBranchesRegex>^.*test.*$</triggeredBranchesRegex>
|
||||
<strategy>INDEXING</strategy>
|
||||
</jenkins.branch.NoTriggerBranchProperty>
|
||||
<org.jenkinsci.plugins.workflow.multibranch.DurabilityHintBranchProperty plugin="workflow-multibranch">
|
||||
<hint>MAX_SURVIVABILITY</hint>
|
||||
</org.jenkinsci.plugins.workflow.multibranch.DurabilityHintBranchProperty>
|
||||
|
@ -45,7 +45,9 @@ scm:
|
||||
verbose-logs: true
|
||||
property-strategies:
|
||||
all-branches:
|
||||
- suppress-scm-triggering: true
|
||||
- suppress-scm-triggering:
|
||||
suppression-strategy: suppress-branch-indexing
|
||||
branch-regex: ^.*test.*$
|
||||
- pipeline-branch-durability-override: max-survivability
|
||||
- trigger-build-on-pr-comment:
|
||||
comment: "Ci build!"
|
||||
|
@ -0,0 +1,81 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject plugin="workflow-multibranch">
|
||||
<properties/>
|
||||
<views>
|
||||
<hudson.model.AllView>
|
||||
<name>All</name>
|
||||
<filterExecutors>false</filterExecutors>
|
||||
<filterQueue>false</filterQueue>
|
||||
<properties class="hudson.model.View$PropertyList"/>
|
||||
<owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../../.."/>
|
||||
</hudson.model.AllView>
|
||||
</views>
|
||||
<viewsTabBar class="hudson.views.DefaultViewsTabBar"/>
|
||||
<folderViews class="jenkins.branch.MultiBranchProjectViewHolder" plugin="branch-api">
|
||||
<owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
|
||||
</folderViews>
|
||||
<healthMetrics>
|
||||
<com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric plugin="cloudbees-folder">
|
||||
<nonRecursive>false</nonRecursive>
|
||||
</com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric>
|
||||
</healthMetrics>
|
||||
<icon class="jenkins.branch.MetadataActionFolderIcon" plugin="branch-api">
|
||||
<owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
|
||||
</icon>
|
||||
<orphanedItemStrategy class="com.cloudbees.hudson.plugins.folder.computed.DefaultOrphanedItemStrategy" plugin="cloudbees-folder">
|
||||
<pruneDeadBranches>true</pruneDeadBranches>
|
||||
<daysToKeep>-1</daysToKeep>
|
||||
<numToKeep>-1</numToKeep>
|
||||
<abortBuilds>false</abortBuilds>
|
||||
</orphanedItemStrategy>
|
||||
<triggers/>
|
||||
<sources class="jenkins.branch.MultiBranchProject$BranchSourceList" plugin="branch-api">
|
||||
<data>
|
||||
<jenkins.branch.BranchSource>
|
||||
<source class="org.jenkinsci.plugins.github_branch_source.GitHubSCMSource" plugin="github-branch-source">
|
||||
<id>gh-johndoe-foo</id>
|
||||
<repoOwner>johndoe</repoOwner>
|
||||
<repository>foo</repository>
|
||||
<traits>
|
||||
<org.jenkinsci.plugins.github__branch__source.BranchDiscoveryTrait>
|
||||
<strategyId>1</strategyId>
|
||||
</org.jenkinsci.plugins.github__branch__source.BranchDiscoveryTrait>
|
||||
<org.jenkinsci.plugins.github__branch__source.ForkPullRequestDiscoveryTrait>
|
||||
<strategyId>1</strategyId>
|
||||
<trust class="org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait$TrustContributors"/>
|
||||
</org.jenkinsci.plugins.github__branch__source.ForkPullRequestDiscoveryTrait>
|
||||
<org.jenkinsci.plugins.github__branch__source.OriginPullRequestDiscoveryTrait>
|
||||
<strategyId>1</strategyId>
|
||||
</org.jenkinsci.plugins.github__branch__source.OriginPullRequestDiscoveryTrait>
|
||||
<jenkins.plugins.git.traits.WipeWorkspaceTrait>
|
||||
<extension class="hudson.plugins.git.extensions.impl.WipeWorkspace"/>
|
||||
</jenkins.plugins.git.traits.WipeWorkspaceTrait>
|
||||
</traits>
|
||||
</source>
|
||||
<strategy class="jenkins.branch.DefaultBranchPropertyStrategy">
|
||||
<properties class="java.util.Arrays$ArrayList">
|
||||
<a class="jenkins.branch.BranchProperty-array">
|
||||
<jenkins.branch.NoTriggerBranchProperty>
|
||||
<triggeredBranchesRegex>^$</triggeredBranchesRegex>
|
||||
<strategy>EVENTS</strategy>
|
||||
</jenkins.branch.NoTriggerBranchProperty>
|
||||
<org.jenkinsci.plugins.workflow.multibranch.DurabilityHintBranchProperty plugin="workflow-multibranch">
|
||||
<hint>MAX_SURVIVABILITY</hint>
|
||||
</org.jenkinsci.plugins.workflow.multibranch.DurabilityHintBranchProperty>
|
||||
<com.adobe.jenkins.github__pr__comment__build.TriggerPRCommentBranchProperty plugin="github-pr-comment-build">
|
||||
<commentBody>Ci build!</commentBody>
|
||||
</com.adobe.jenkins.github__pr__comment__build.TriggerPRCommentBranchProperty>
|
||||
<com.adobe.jenkins.github__pr__comment__build.TriggerPRReviewBranchProperty plugin="github-pr-comment-build"/>
|
||||
<com.adobe.jenkins.github__pr__comment__build.TriggerPRUpdateBranchProperty plugin="github-pr-comment-build"/>
|
||||
</a>
|
||||
</properties>
|
||||
</strategy>
|
||||
</jenkins.branch.BranchSource>
|
||||
</data>
|
||||
<owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
|
||||
</sources>
|
||||
<factory class="org.jenkinsci.plugins.workflow.multibranch.WorkflowBranchProjectFactory">
|
||||
<owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
|
||||
<scriptPath>Jenkinsfile</scriptPath>
|
||||
</factory>
|
||||
</org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject>
|
@ -0,0 +1,16 @@
|
||||
name: 'demo-multibranch-github-min'
|
||||
project-type: multibranch
|
||||
scm:
|
||||
- github:
|
||||
repo: 'foo'
|
||||
repo-owner: 'johndoe'
|
||||
|
||||
property-strategies:
|
||||
all-branches:
|
||||
- suppress-scm-triggering:
|
||||
suppression-strategy: suppress-webhooks
|
||||
branch-regex: ^$
|
||||
- pipeline-branch-durability-override: max-survivability
|
||||
- trigger-build-on-pr-comment: "Ci build!"
|
||||
- trigger-build-on-pr-review: true
|
||||
- trigger-build-on-pr-update: true
|
@ -0,0 +1,77 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject plugin="workflow-multibranch">
|
||||
<properties/>
|
||||
<views>
|
||||
<hudson.model.AllView>
|
||||
<name>All</name>
|
||||
<filterExecutors>false</filterExecutors>
|
||||
<filterQueue>false</filterQueue>
|
||||
<properties class="hudson.model.View$PropertyList"/>
|
||||
<owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../../.."/>
|
||||
</hudson.model.AllView>
|
||||
</views>
|
||||
<viewsTabBar class="hudson.views.DefaultViewsTabBar"/>
|
||||
<folderViews class="jenkins.branch.MultiBranchProjectViewHolder" plugin="branch-api">
|
||||
<owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
|
||||
</folderViews>
|
||||
<healthMetrics>
|
||||
<com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric plugin="cloudbees-folder">
|
||||
<nonRecursive>false</nonRecursive>
|
||||
</com.cloudbees.hudson.plugins.folder.health.WorstChildHealthMetric>
|
||||
</healthMetrics>
|
||||
<icon class="jenkins.branch.MetadataActionFolderIcon" plugin="branch-api">
|
||||
<owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
|
||||
</icon>
|
||||
<orphanedItemStrategy class="com.cloudbees.hudson.plugins.folder.computed.DefaultOrphanedItemStrategy" plugin="cloudbees-folder">
|
||||
<pruneDeadBranches>true</pruneDeadBranches>
|
||||
<daysToKeep>-1</daysToKeep>
|
||||
<numToKeep>-1</numToKeep>
|
||||
<abortBuilds>false</abortBuilds>
|
||||
</orphanedItemStrategy>
|
||||
<triggers/>
|
||||
<sources class="jenkins.branch.MultiBranchProject$BranchSourceList" plugin="branch-api">
|
||||
<data>
|
||||
<jenkins.branch.BranchSource>
|
||||
<source class="org.jenkinsci.plugins.github_branch_source.GitHubSCMSource" plugin="github-branch-source">
|
||||
<id>gh-johndoe-foo</id>
|
||||
<repoOwner>johndoe</repoOwner>
|
||||
<repository>foo</repository>
|
||||
<traits>
|
||||
<org.jenkinsci.plugins.github__branch__source.BranchDiscoveryTrait>
|
||||
<strategyId>1</strategyId>
|
||||
</org.jenkinsci.plugins.github__branch__source.BranchDiscoveryTrait>
|
||||
<org.jenkinsci.plugins.github__branch__source.ForkPullRequestDiscoveryTrait>
|
||||
<strategyId>1</strategyId>
|
||||
<trust class="org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait$TrustContributors"/>
|
||||
</org.jenkinsci.plugins.github__branch__source.ForkPullRequestDiscoveryTrait>
|
||||
<org.jenkinsci.plugins.github__branch__source.OriginPullRequestDiscoveryTrait>
|
||||
<strategyId>1</strategyId>
|
||||
</org.jenkinsci.plugins.github__branch__source.OriginPullRequestDiscoveryTrait>
|
||||
<jenkins.plugins.git.traits.WipeWorkspaceTrait>
|
||||
<extension class="hudson.plugins.git.extensions.impl.WipeWorkspace"/>
|
||||
</jenkins.plugins.git.traits.WipeWorkspaceTrait>
|
||||
</traits>
|
||||
</source>
|
||||
<strategy class="jenkins.branch.DefaultBranchPropertyStrategy">
|
||||
<properties class="java.util.Arrays$ArrayList">
|
||||
<a class="jenkins.branch.BranchProperty-array">
|
||||
<org.jenkinsci.plugins.workflow.multibranch.DurabilityHintBranchProperty plugin="workflow-multibranch">
|
||||
<hint>MAX_SURVIVABILITY</hint>
|
||||
</org.jenkinsci.plugins.workflow.multibranch.DurabilityHintBranchProperty>
|
||||
<com.adobe.jenkins.github__pr__comment__build.TriggerPRCommentBranchProperty plugin="github-pr-comment-build">
|
||||
<commentBody>Ci build!</commentBody>
|
||||
</com.adobe.jenkins.github__pr__comment__build.TriggerPRCommentBranchProperty>
|
||||
<com.adobe.jenkins.github__pr__comment__build.TriggerPRReviewBranchProperty plugin="github-pr-comment-build"/>
|
||||
<com.adobe.jenkins.github__pr__comment__build.TriggerPRUpdateBranchProperty plugin="github-pr-comment-build"/>
|
||||
</a>
|
||||
</properties>
|
||||
</strategy>
|
||||
</jenkins.branch.BranchSource>
|
||||
</data>
|
||||
<owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
|
||||
</sources>
|
||||
<factory class="org.jenkinsci.plugins.workflow.multibranch.WorkflowBranchProjectFactory">
|
||||
<owner class="org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject" reference="../.."/>
|
||||
<scriptPath>Jenkinsfile</scriptPath>
|
||||
</factory>
|
||||
</org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject>
|
@ -0,0 +1,14 @@
|
||||
name: 'demo-multibranch-github-min'
|
||||
project-type: multibranch
|
||||
scm:
|
||||
- github:
|
||||
repo: 'foo'
|
||||
repo-owner: 'johndoe'
|
||||
|
||||
property-strategies:
|
||||
all-branches:
|
||||
- suppress-scm-triggering: false
|
||||
- pipeline-branch-durability-override: max-survivability
|
||||
- trigger-build-on-pr-comment: "Ci build!"
|
||||
- trigger-build-on-pr-review: true
|
||||
- trigger-build-on-pr-update: true
|
Loading…
Reference in New Issue
Block a user