Adds support for Property Strategies
Multibranch pipeline jobs also support "Property Strategy" elements. These are fairly limited, but do contain the very useful "Suppress automatic SCM triggering" trait. This commit adds support for defining these for the "All branches get the same properties" strategy, and could be easily amended to also support the "Named branches get different properties" strategy in a future update. Change-Id: I3d9281657e341260a23f357f6e247793379b0eed Signed-off-by: sbussetti <steve.bussetti@gmail.com>
This commit is contained in:
parent
d29998eaa9
commit
dbbca01833
@ -325,6 +325,10 @@ def bitbucket_scm(xml_parent, data):
|
|||||||
discovered initially or a change from the previous revision has been
|
discovered initially or a change from the previous revision has been
|
||||||
detected. (optional)
|
detected. (optional)
|
||||||
Refer to :func:`~build_strategies <build_strategies>`.
|
Refer to :func:`~build_strategies <build_strategies>`.
|
||||||
|
:arg dict property-strategies: Provides control over how to build a branch
|
||||||
|
(like to disable SCM triggering or to override the pipeline durability)
|
||||||
|
(optional)
|
||||||
|
Refer to :func:`~property_strategies <property_strategies>`.
|
||||||
:arg bool local-branch: Check out to matching local branch
|
:arg bool local-branch: Check out to matching local branch
|
||||||
If given, checkout the revision to build as HEAD on this branch.
|
If given, checkout the revision to build as HEAD on this branch.
|
||||||
If selected, then the branch name is computed from the remote branch
|
If selected, then the branch name is computed from the remote branch
|
||||||
@ -485,6 +489,9 @@ def bitbucket_scm(xml_parent, data):
|
|||||||
helpers.convert_mapping_to_xml(
|
helpers.convert_mapping_to_xml(
|
||||||
dbr, data, dbr_mapping, fail_required=True)
|
dbr, data, dbr_mapping, fail_required=True)
|
||||||
|
|
||||||
|
if data.get('property-strategies', None):
|
||||||
|
property_strategies(xml_parent, data)
|
||||||
|
|
||||||
if data.get('build-strategies', None):
|
if data.get('build-strategies', None):
|
||||||
build_strategies(xml_parent, data)
|
build_strategies(xml_parent, data)
|
||||||
|
|
||||||
@ -564,6 +571,10 @@ def gerrit_scm(xml_parent, data):
|
|||||||
discovered initially or a change from the previous revision has been
|
discovered initially or a change from the previous revision has been
|
||||||
detected. (optional)
|
detected. (optional)
|
||||||
Refer to :func:`~build_strategies <build_strategies>`.
|
Refer to :func:`~build_strategies <build_strategies>`.
|
||||||
|
:arg dict property-strategies: Provides control over how to build a branch
|
||||||
|
(like to disable SCM triggering or to override the pipeline durability)
|
||||||
|
(optional)
|
||||||
|
Refer to :func:`~property_strategies <property_strategies>`.
|
||||||
|
|
||||||
Minimal Example:
|
Minimal Example:
|
||||||
|
|
||||||
@ -621,6 +632,9 @@ def gerrit_scm(xml_parent, data):
|
|||||||
'.RefSpecsSCMSourceTrait_-RefSpecTemplate'))
|
'.RefSpecsSCMSourceTrait_-RefSpecTemplate'))
|
||||||
XML.SubElement(e, 'value').text = x
|
XML.SubElement(e, 'value').text = x
|
||||||
|
|
||||||
|
if data.get('property-strategies', None):
|
||||||
|
property_strategies(xml_parent, data)
|
||||||
|
|
||||||
if data.get('build-strategies', None):
|
if data.get('build-strategies', None):
|
||||||
build_strategies(xml_parent, data)
|
build_strategies(xml_parent, data)
|
||||||
|
|
||||||
@ -648,6 +662,10 @@ def git_scm(xml_parent, data):
|
|||||||
discovered initially or a change from the previous revision has been
|
discovered initially or a change from the previous revision has been
|
||||||
detected. (optional)
|
detected. (optional)
|
||||||
Refer to :func:`~build_strategies <build_strategies>`.
|
Refer to :func:`~build_strategies <build_strategies>`.
|
||||||
|
:arg dict property-strategies: Provides control over how to build a branch
|
||||||
|
(like to disable SCM triggering or to override the pipeline durability)
|
||||||
|
(optional)
|
||||||
|
Refer to :func:`~property_strategies <property_strategies>`.
|
||||||
|
|
||||||
:extensions:
|
:extensions:
|
||||||
|
|
||||||
@ -722,6 +740,9 @@ def git_scm(xml_parent, data):
|
|||||||
'jenkins.scm.impl.trait.RegexSCMHeadFilterTrait')
|
'jenkins.scm.impl.trait.RegexSCMHeadFilterTrait')
|
||||||
XML.SubElement(rshf, 'regex').text = data.get('head-filter-regex')
|
XML.SubElement(rshf, 'regex').text = data.get('head-filter-regex')
|
||||||
|
|
||||||
|
if data.get('property-strategies', None):
|
||||||
|
property_strategies(xml_parent, data)
|
||||||
|
|
||||||
if data.get('build-strategies', None):
|
if data.get('build-strategies', None):
|
||||||
build_strategies(xml_parent, data)
|
build_strategies(xml_parent, data)
|
||||||
|
|
||||||
@ -774,6 +795,10 @@ def github_scm(xml_parent, data):
|
|||||||
discovered initially or a change from the previous revision has been
|
discovered initially or a change from the previous revision has been
|
||||||
detected. (optional)
|
detected. (optional)
|
||||||
Refer to :func:`~build_strategies <build_strategies>`.
|
Refer to :func:`~build_strategies <build_strategies>`.
|
||||||
|
:arg dict property-strategies: Provides control over how to build a branch
|
||||||
|
(like to disable SCM triggering or to override the pipeline durability)
|
||||||
|
(optional)
|
||||||
|
Refer to :func:`~property_strategies <property_strategies>`.
|
||||||
|
|
||||||
:extensions:
|
:extensions:
|
||||||
|
|
||||||
@ -943,6 +968,9 @@ def github_scm(xml_parent, data):
|
|||||||
helpers.convert_mapping_to_xml(
|
helpers.convert_mapping_to_xml(
|
||||||
dpro, data, dpro_mapping, fail_required=True)
|
dpro, data, dpro_mapping, fail_required=True)
|
||||||
|
|
||||||
|
if data.get('property-strategies', None):
|
||||||
|
property_strategies(xml_parent, data)
|
||||||
|
|
||||||
if data.get('build-strategies', None):
|
if data.get('build-strategies', None):
|
||||||
build_strategies(xml_parent, data)
|
build_strategies(xml_parent, data)
|
||||||
|
|
||||||
@ -1106,3 +1134,62 @@ def build_strategies(xml_parent, data):
|
|||||||
nb['wildcards-name'],
|
nb['wildcards-name'],
|
||||||
wildcards_name_mapping,
|
wildcards_name_mapping,
|
||||||
fail_required=False)
|
fail_required=False)
|
||||||
|
|
||||||
|
|
||||||
|
def property_strategies(xml_parent, data):
|
||||||
|
"""Configure Basic Branch Property Strategies.
|
||||||
|
|
||||||
|
Requires the :jenkins-wiki:`Branch API Plugin <Branch+API+Plugin>`.
|
||||||
|
|
||||||
|
:arg dict property-strategies: Definition of property strategies.
|
||||||
|
|
||||||
|
* **all-branches** (list): A list of property strategy definitions
|
||||||
|
for use with all branches.
|
||||||
|
|
||||||
|
* **suppress-scm-triggering** (bool): Suppresses automatic SCM
|
||||||
|
triggering (optional)
|
||||||
|
* **pipeline-branch-durability-override** (str): Set a custom
|
||||||
|
branch speed/durability level. Valid values:
|
||||||
|
performance-optimized, survivable-nonatomic, or
|
||||||
|
max-survivability (optional) Requires the :jenkins-wiki:
|
||||||
|
`Pipeline Multibranch Plugin <Pipeline+Multibranch+Plugin>`
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Valid options for the pipeline branch durability override.
|
||||||
|
pbdo_map = collections.OrderedDict([
|
||||||
|
("max-survivability", "MAX_SURVIVABILITY"),
|
||||||
|
("performance-optimized", "PERFORMANCE_OPTIMIZED"),
|
||||||
|
("survivable-nonatomic", "SURVIVABLE_NONATOMIC"),
|
||||||
|
])
|
||||||
|
basic_property_strategies = 'jenkins.branch'
|
||||||
|
workflow_multibranch = 'org.jenkinsci.plugins.workflow.multibranch'
|
||||||
|
dbps = XML.SubElement(xml_parent, 'strategy', {
|
||||||
|
'class': ''.join([basic_property_strategies,
|
||||||
|
'.DefaultBranchPropertyStrategy'])})
|
||||||
|
prop_strats = data.get('property-strategies', None)
|
||||||
|
|
||||||
|
if prop_strats:
|
||||||
|
props_elem = XML.SubElement(dbps, 'properties', {
|
||||||
|
'class': 'java.util.Arrays$ArrayList'})
|
||||||
|
props_elem = XML.SubElement(props_elem, 'a', {
|
||||||
|
'class': ''.join([
|
||||||
|
basic_property_strategies, '.BranchProperty-array'])})
|
||||||
|
|
||||||
|
for dbs_list in prop_strats.get('all-branches', None):
|
||||||
|
|
||||||
|
if dbs_list.get('suppress-scm-triggering', False):
|
||||||
|
XML.SubElement(props_elem, ''.join([
|
||||||
|
basic_property_strategies, '.NoTriggerBranchProperty']))
|
||||||
|
|
||||||
|
pbdo_val = dbs_list.get(
|
||||||
|
'pipeline-branch-durability-override', None)
|
||||||
|
if pbdo_val:
|
||||||
|
if not pbdo_map.get(pbdo_val):
|
||||||
|
raise InvalidAttributeError(
|
||||||
|
'pipeline-branch-durability-override',
|
||||||
|
pbdo_val,
|
||||||
|
pbdo_map.keys())
|
||||||
|
pbdo_elem = XML.SubElement(props_elem, ''.join([
|
||||||
|
workflow_multibranch, '.DurabilityHintBranchProperty']), {
|
||||||
|
'plugin': 'workflow-multibranch'})
|
||||||
|
XML.SubElement(pbdo_elem, 'hint').text = pbdo_map.get(pbdo_val)
|
||||||
|
@ -104,6 +104,16 @@
|
|||||||
</jenkins.plugins.git.traits.AuthorInChangelogTrait>
|
</jenkins.plugins.git.traits.AuthorInChangelogTrait>
|
||||||
</traits>
|
</traits>
|
||||||
</source>
|
</source>
|
||||||
|
<strategy class="jenkins.branch.DefaultBranchPropertyStrategy">
|
||||||
|
<properties class="java.util.Arrays$ArrayList">
|
||||||
|
<a class="jenkins.branch.BranchProperty-array">
|
||||||
|
<jenkins.branch.NoTriggerBranchProperty/>
|
||||||
|
<org.jenkinsci.plugins.workflow.multibranch.DurabilityHintBranchProperty plugin="workflow-multibranch">
|
||||||
|
<hint>MAX_SURVIVABILITY</hint>
|
||||||
|
</org.jenkinsci.plugins.workflow.multibranch.DurabilityHintBranchProperty>
|
||||||
|
</a>
|
||||||
|
</properties>
|
||||||
|
</strategy>
|
||||||
<buildStrategies>
|
<buildStrategies>
|
||||||
<jenkins.branch.buildstrategies.basic.TagBuildStrategyImpl plugin="basic-branch-build-strategies">
|
<jenkins.branch.buildstrategies.basic.TagBuildStrategyImpl plugin="basic-branch-build-strategies">
|
||||||
<atMostMillis>86400000</atMostMillis>
|
<atMostMillis>86400000</atMostMillis>
|
||||||
|
@ -19,6 +19,10 @@ scm:
|
|||||||
filter-by-name-wildcard:
|
filter-by-name-wildcard:
|
||||||
includes: '*'
|
includes: '*'
|
||||||
excludes: 'master'
|
excludes: 'master'
|
||||||
|
property-strategies:
|
||||||
|
all-branches:
|
||||||
|
- suppress-scm-triggering: true
|
||||||
|
- pipeline-branch-durability-override: max-survivability
|
||||||
build-strategies:
|
build-strategies:
|
||||||
- tags:
|
- tags:
|
||||||
ignore-tags-newer-than: 1
|
ignore-tags-newer-than: 1
|
||||||
|
@ -49,6 +49,16 @@
|
|||||||
</jenkins.plugins.git.traits.RefSpecsSCMSourceTrait>
|
</jenkins.plugins.git.traits.RefSpecsSCMSourceTrait>
|
||||||
</traits>
|
</traits>
|
||||||
</source>
|
</source>
|
||||||
|
<strategy class="jenkins.branch.DefaultBranchPropertyStrategy">
|
||||||
|
<properties class="java.util.Arrays$ArrayList">
|
||||||
|
<a class="jenkins.branch.BranchProperty-array">
|
||||||
|
<jenkins.branch.NoTriggerBranchProperty/>
|
||||||
|
<org.jenkinsci.plugins.workflow.multibranch.DurabilityHintBranchProperty plugin="workflow-multibranch">
|
||||||
|
<hint>MAX_SURVIVABILITY</hint>
|
||||||
|
</org.jenkinsci.plugins.workflow.multibranch.DurabilityHintBranchProperty>
|
||||||
|
</a>
|
||||||
|
</properties>
|
||||||
|
</strategy>
|
||||||
<buildStrategies>
|
<buildStrategies>
|
||||||
<jenkins.branch.buildstrategies.basic.TagBuildStrategyImpl plugin="basic-branch-build-strategies">
|
<jenkins.branch.buildstrategies.basic.TagBuildStrategyImpl plugin="basic-branch-build-strategies">
|
||||||
<atMostMillis>86400000</atMostMillis>
|
<atMostMillis>86400000</atMostMillis>
|
||||||
|
@ -7,6 +7,10 @@ scm:
|
|||||||
credentials-id: secret
|
credentials-id: secret
|
||||||
ignore-on-push-notifications: true
|
ignore-on-push-notifications: true
|
||||||
refspecs: 'refs/heads/*'
|
refspecs: 'refs/heads/*'
|
||||||
|
property-strategies:
|
||||||
|
all-branches:
|
||||||
|
- suppress-scm-triggering: true
|
||||||
|
- pipeline-branch-durability-override: max-survivability
|
||||||
build-strategies:
|
build-strategies:
|
||||||
- tags:
|
- tags:
|
||||||
ignore-tags-newer-than: 1
|
ignore-tags-newer-than: 1
|
||||||
|
@ -81,6 +81,16 @@
|
|||||||
</jenkins.plugins.git.traits.AuthorInChangelogTrait>
|
</jenkins.plugins.git.traits.AuthorInChangelogTrait>
|
||||||
</traits>
|
</traits>
|
||||||
</source>
|
</source>
|
||||||
|
<strategy class="jenkins.branch.DefaultBranchPropertyStrategy">
|
||||||
|
<properties class="java.util.Arrays$ArrayList">
|
||||||
|
<a class="jenkins.branch.BranchProperty-array">
|
||||||
|
<jenkins.branch.NoTriggerBranchProperty/>
|
||||||
|
<org.jenkinsci.plugins.workflow.multibranch.DurabilityHintBranchProperty plugin="workflow-multibranch">
|
||||||
|
<hint>MAX_SURVIVABILITY</hint>
|
||||||
|
</org.jenkinsci.plugins.workflow.multibranch.DurabilityHintBranchProperty>
|
||||||
|
</a>
|
||||||
|
</properties>
|
||||||
|
</strategy>
|
||||||
<buildStrategies>
|
<buildStrategies>
|
||||||
<jenkins.branch.buildstrategies.basic.TagBuildStrategyImpl plugin="basic-branch-build-strategies">
|
<jenkins.branch.buildstrategies.basic.TagBuildStrategyImpl plugin="basic-branch-build-strategies">
|
||||||
<atMostMillis>86400000</atMostMillis>
|
<atMostMillis>86400000</atMostMillis>
|
||||||
|
@ -9,6 +9,10 @@ scm:
|
|||||||
ignore-on-push-notifications: true
|
ignore-on-push-notifications: true
|
||||||
discover-tags: true
|
discover-tags: true
|
||||||
head-filter-regex: 'master|\d+\.\d+'
|
head-filter-regex: 'master|\d+\.\d+'
|
||||||
|
property-strategies:
|
||||||
|
all-branches:
|
||||||
|
- suppress-scm-triggering: true
|
||||||
|
- pipeline-branch-durability-override: max-survivability
|
||||||
build-strategies:
|
build-strategies:
|
||||||
- tags:
|
- tags:
|
||||||
ignore-tags-newer-than: 1
|
ignore-tags-newer-than: 1
|
||||||
|
@ -93,6 +93,16 @@
|
|||||||
<com.adobe.jenkins.disable__github__multibranch__status.DisableStatusUpdateTrait plugin="disable-github-multibranch-status"/>
|
<com.adobe.jenkins.disable__github__multibranch__status.DisableStatusUpdateTrait plugin="disable-github-multibranch-status"/>
|
||||||
</traits>
|
</traits>
|
||||||
</source>
|
</source>
|
||||||
|
<strategy class="jenkins.branch.DefaultBranchPropertyStrategy">
|
||||||
|
<properties class="java.util.Arrays$ArrayList">
|
||||||
|
<a class="jenkins.branch.BranchProperty-array">
|
||||||
|
<jenkins.branch.NoTriggerBranchProperty/>
|
||||||
|
<org.jenkinsci.plugins.workflow.multibranch.DurabilityHintBranchProperty plugin="workflow-multibranch">
|
||||||
|
<hint>MAX_SURVIVABILITY</hint>
|
||||||
|
</org.jenkinsci.plugins.workflow.multibranch.DurabilityHintBranchProperty>
|
||||||
|
</a>
|
||||||
|
</properties>
|
||||||
|
</strategy>
|
||||||
<buildStrategies>
|
<buildStrategies>
|
||||||
<jenkins.branch.buildstrategies.basic.TagBuildStrategyImpl plugin="basic-branch-build-strategies">
|
<jenkins.branch.buildstrategies.basic.TagBuildStrategyImpl plugin="basic-branch-build-strategies">
|
||||||
<atMostMillis>86400000</atMostMillis>
|
<atMostMillis>86400000</atMostMillis>
|
||||||
|
@ -14,6 +14,10 @@ scm:
|
|||||||
discover-pr-forks-trust: everyone
|
discover-pr-forks-trust: everyone
|
||||||
discover-pr-origin: both
|
discover-pr-origin: both
|
||||||
discover-tags: true
|
discover-tags: true
|
||||||
|
property-strategies:
|
||||||
|
all-branches:
|
||||||
|
- suppress-scm-triggering: true
|
||||||
|
- pipeline-branch-durability-override: max-survivability
|
||||||
build-strategies:
|
build-strategies:
|
||||||
- tags:
|
- tags:
|
||||||
ignore-tags-newer-than: 1
|
ignore-tags-newer-than: 1
|
||||||
|
Loading…
Reference in New Issue
Block a user