Merge "Added configuration for Suppress SCM Triggering"

This commit is contained in:
Zuul 2023-03-31 15:14:05 +00:00 committed by Gerrit Code Review
commit 589023d5c4
15 changed files with 352 additions and 10 deletions

View File

@ -1460,8 +1460,21 @@ def property_strategies(xml_parent, data):
* **all-branches** (list): A list of property strategy definitions * **all-branches** (list): A list of property strategy definitions
for use with all branches. for use with all branches.
* **suppress-scm-triggering** (bool): Suppresses automatic SCM * **suppress-scm-triggering** (dict):
triggering (optional) 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 * **pipeline-branch-durability-override** (str): Set a custom
branch speed/durability level. Valid values: branch speed/durability level. Valid values:
performance-optimized, survivable-nonatomic, or 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 to be applied by default to all branches, unless overridden
by an entry in `exceptions` by an entry in `exceptions`
* **suppress-scm-triggering** (bool): Suppresses automatic SCM * **suppress-scm-triggering** (dict):
triggering (optional) 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 * **pipeline-branch-durability-override** (str): Set a custom
branch speed/durability level. Valid values: branch speed/durability level. Valid values:
performance-optimized, survivable-nonatomic, or performance-optimized, survivable-nonatomic, or
@ -1562,8 +1588,22 @@ def property_strategies(xml_parent, data):
* **properties** (list): A list of properties to apply to * **properties** (list): A list of properties to apply to
this branch. this branch.
* **suppress-scm-triggering** (bool): Suppresses * **suppress-scm-triggering** (dict):
automatic SCM triggering (optional) 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 * **pipeline-branch-durability-override** (str): Set a
custom branch speed/durability level. Valid values: custom branch speed/durability level. Valid values:
performance-optimized, survivable-nonatomic, or 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: for dbs_list in props_list:
if dbs_list.get("suppress-scm-triggering", False): sst_val = dbs_list.get("suppress-scm-triggering", False)
XML.SubElement( if sst_val:
sst_elem = XML.SubElement(
props_elem, props_elem,
"".join([basic_property_strategies, ".NoTriggerBranchProperty"]), "".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) pbdo_val = dbs_list.get("pipeline-branch-durability-override", None)
if pbdo_val: if pbdo_val:
if not pbdo_map.get(pbdo_val): if not pbdo_map.get(pbdo_val):

View File

@ -0,0 +1 @@
'['test']' is an invalid value for attribute name.suppress-scm-triggering

View File

@ -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

View File

@ -0,0 +1 @@
Missing suppress-scm-triggering[branch-regex] from an instance of 'name'

View File

@ -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

View File

@ -0,0 +1 @@
Missing suppress-scm-triggering[suppression-strategy] from an instance of 'name'

View File

@ -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

View File

@ -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'

View File

@ -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

View File

@ -167,7 +167,10 @@
<strategy class="jenkins.branch.DefaultBranchPropertyStrategy"> <strategy class="jenkins.branch.DefaultBranchPropertyStrategy">
<properties class="java.util.Arrays$ArrayList"> <properties class="java.util.Arrays$ArrayList">
<a class="jenkins.branch.BranchProperty-array"> <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"> <org.jenkinsci.plugins.workflow.multibranch.DurabilityHintBranchProperty plugin="workflow-multibranch">
<hint>MAX_SURVIVABILITY</hint> <hint>MAX_SURVIVABILITY</hint>
</org.jenkinsci.plugins.workflow.multibranch.DurabilityHintBranchProperty> </org.jenkinsci.plugins.workflow.multibranch.DurabilityHintBranchProperty>

View File

@ -45,7 +45,9 @@ scm:
verbose-logs: true verbose-logs: true
property-strategies: property-strategies:
all-branches: all-branches:
- suppress-scm-triggering: true - suppress-scm-triggering:
suppression-strategy: suppress-branch-indexing
branch-regex: ^.*test.*$
- pipeline-branch-durability-override: max-survivability - pipeline-branch-durability-override: max-survivability
- trigger-build-on-pr-comment: - trigger-build-on-pr-comment:
comment: "Ci build!" comment: "Ci build!"

View File

@ -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>

View File

@ -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

View File

@ -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>

View File

@ -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