Fix parameters overrides in dimensions specification
Task: 48621 Story: 2010883 Change-Id: Ia267f66c3832fb4a42a54a86bda259e96bb191fd
This commit is contained in:
parent
0f29e2ea3a
commit
d62faa15d4
@ -11,12 +11,16 @@
|
||||
# under the License.
|
||||
|
||||
import itertools
|
||||
from collections import namedtuple
|
||||
|
||||
from .errors import Context, JenkinsJobsException
|
||||
from .loc_loader import LocList, LocDict
|
||||
from jenkins_jobs.expander import Expander
|
||||
|
||||
|
||||
Dimension = namedtuple("Dimension", "axis params")
|
||||
|
||||
|
||||
def _decode_axis_value(axis, value, key_pos, value_pos):
|
||||
if not isinstance(value, (list, LocList)):
|
||||
yield {axis: value}
|
||||
@ -59,10 +63,20 @@ def enum_dimensions_params(axes, params, defaults):
|
||||
except KeyError:
|
||||
continue # May be, value would be received from an another axis values.
|
||||
expanded_value = expander.expand(value, params)
|
||||
value = list(_decode_axis_value(axis, expanded_value, key_pos, value_pos))
|
||||
value = [
|
||||
Dimension(axis, params)
|
||||
for params in _decode_axis_value(axis, expanded_value, key_pos, value_pos)
|
||||
]
|
||||
dim_values.append(value)
|
||||
for values in itertools.product(*dim_values):
|
||||
yield LocDict.merge(*values)
|
||||
for dimensions in itertools.product(*dim_values):
|
||||
overrides = {} # Axis -> overridden param.
|
||||
for dim in dimensions:
|
||||
for name, value in dim.params.items():
|
||||
if name != dim.axis:
|
||||
overrides[name] = value
|
||||
param_dicts = [d.params for d in dimensions]
|
||||
# Parameter overrides should take precedence over axis values.
|
||||
yield LocDict.merge(*param_dicts, overrides)
|
||||
|
||||
|
||||
def _match_exclude(params, exclude, pos):
|
||||
|
@ -8,7 +8,6 @@
|
||||
- shell: |
|
||||
echo {param_1} {param_2}
|
||||
|
||||
|
||||
- project:
|
||||
name: sample-project
|
||||
param_1:
|
||||
|
@ -0,0 +1,57 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<actions/>
|
||||
<description><!-- Managed by Jenkins Job Builder --></description>
|
||||
<keepDependencies>false</keepDependencies>
|
||||
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
|
||||
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
|
||||
<concurrentBuild>false</concurrentBuild>
|
||||
<canRoam>true</canRoam>
|
||||
<properties/>
|
||||
<scm class="hudson.scm.NullSCM"/>
|
||||
<builders>
|
||||
<hudson.tasks.Shell>
|
||||
<command>echo param_1_key param_1_param_2_value_1</command>
|
||||
</hudson.tasks.Shell>
|
||||
</builders>
|
||||
<publishers/>
|
||||
<buildWrappers/>
|
||||
</project>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<actions/>
|
||||
<description><!-- Managed by Jenkins Job Builder --></description>
|
||||
<keepDependencies>false</keepDependencies>
|
||||
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
|
||||
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
|
||||
<concurrentBuild>false</concurrentBuild>
|
||||
<canRoam>true</canRoam>
|
||||
<properties/>
|
||||
<scm class="hudson.scm.NullSCM"/>
|
||||
<builders>
|
||||
<hudson.tasks.Shell>
|
||||
<command>echo param_2_param_1_value_1 param_2_param_2_value_2</command>
|
||||
</hudson.tasks.Shell>
|
||||
</builders>
|
||||
<publishers/>
|
||||
<buildWrappers/>
|
||||
</project>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<actions/>
|
||||
<description><!-- Managed by Jenkins Job Builder --></description>
|
||||
<keepDependencies>false</keepDependencies>
|
||||
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
|
||||
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
|
||||
<concurrentBuild>false</concurrentBuild>
|
||||
<canRoam>true</canRoam>
|
||||
<properties/>
|
||||
<scm class="hudson.scm.NullSCM"/>
|
||||
<builders>
|
||||
<hudson.tasks.Shell>
|
||||
<command>echo param_3_key param_2_value</command>
|
||||
</hudson.tasks.Shell>
|
||||
</builders>
|
||||
<publishers/>
|
||||
<buildWrappers/>
|
||||
</project>
|
@ -0,0 +1,20 @@
|
||||
# If a parameter with the same name as dimension name specified, it's value
|
||||
# should be used as dimension parameter value.
|
||||
|
||||
- job-template:
|
||||
name: job-{param_1}-{param_2}
|
||||
builders:
|
||||
- shell: echo {param_1} {param_2}
|
||||
|
||||
- project:
|
||||
name: sample-project
|
||||
param_1:
|
||||
- param_1_key:
|
||||
param_2: param_1_param_2_value_1
|
||||
- param_2_key:
|
||||
param_1: param_2_param_1_value_1
|
||||
param_2: param_2_param_2_value_2
|
||||
- param_3_key
|
||||
param_2: param_2_value
|
||||
jobs:
|
||||
- job-{param_1}-{param_2}
|
76
tests/yamlparser/job_fixtures/regression-2010883.xml
Normal file
76
tests/yamlparser/job_fixtures/regression-2010883.xml
Normal file
@ -0,0 +1,76 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<actions/>
|
||||
<description><!-- Managed by Jenkins Job Builder --></description>
|
||||
<keepDependencies>false</keepDependencies>
|
||||
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
|
||||
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
|
||||
<concurrentBuild>false</concurrentBuild>
|
||||
<canRoam>true</canRoam>
|
||||
<properties/>
|
||||
<scm class="hudson.scm.NullSCM"/>
|
||||
<builders>
|
||||
<hudson.tasks.Shell>
|
||||
<command>echo The prod orchard has apple trees</command>
|
||||
</hudson.tasks.Shell>
|
||||
</builders>
|
||||
<publishers/>
|
||||
<buildWrappers/>
|
||||
</project>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<actions/>
|
||||
<description><!-- Managed by Jenkins Job Builder --></description>
|
||||
<keepDependencies>false</keepDependencies>
|
||||
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
|
||||
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
|
||||
<concurrentBuild>false</concurrentBuild>
|
||||
<canRoam>true</canRoam>
|
||||
<properties/>
|
||||
<scm class="hudson.scm.NullSCM"/>
|
||||
<builders>
|
||||
<hudson.tasks.Shell>
|
||||
<command>echo The qa orchard has apple trees</command>
|
||||
</hudson.tasks.Shell>
|
||||
</builders>
|
||||
<publishers/>
|
||||
<buildWrappers/>
|
||||
</project>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<actions/>
|
||||
<description><!-- Managed by Jenkins Job Builder --></description>
|
||||
<keepDependencies>false</keepDependencies>
|
||||
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
|
||||
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
|
||||
<concurrentBuild>false</concurrentBuild>
|
||||
<canRoam>true</canRoam>
|
||||
<properties/>
|
||||
<scm class="hudson.scm.NullSCM"/>
|
||||
<builders>
|
||||
<hudson.tasks.Shell>
|
||||
<command>echo The sandbox orchard has cherry trees</command>
|
||||
</hudson.tasks.Shell>
|
||||
</builders>
|
||||
<publishers/>
|
||||
<buildWrappers/>
|
||||
</project>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<actions/>
|
||||
<description><!-- Managed by Jenkins Job Builder --></description>
|
||||
<keepDependencies>false</keepDependencies>
|
||||
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
|
||||
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
|
||||
<concurrentBuild>false</concurrentBuild>
|
||||
<canRoam>true</canRoam>
|
||||
<properties/>
|
||||
<scm class="hudson.scm.NullSCM"/>
|
||||
<builders>
|
||||
<hudson.tasks.Shell>
|
||||
<command>echo The sandbox orchard has orange trees</command>
|
||||
</hudson.tasks.Shell>
|
||||
</builders>
|
||||
<publishers/>
|
||||
<buildWrappers/>
|
||||
</project>
|
17
tests/yamlparser/job_fixtures/regression-2010883.yaml
Normal file
17
tests/yamlparser/job_fixtures/regression-2010883.yaml
Normal file
@ -0,0 +1,17 @@
|
||||
- job-template:
|
||||
name: '{environment}-{fruit}-orchard'
|
||||
builders:
|
||||
- shell: 'echo The {environment} orchard has {fruit} trees'
|
||||
|
||||
- project:
|
||||
name: 'Fruit orchard'
|
||||
environment:
|
||||
- sandbox:
|
||||
fruit: 'orange'
|
||||
- sandbox:
|
||||
fruit: 'cherry'
|
||||
- qa
|
||||
- prod
|
||||
fruit: apple
|
||||
jobs:
|
||||
- '{environment}-{fruit}-orchard'
|
Loading…
x
Reference in New Issue
Block a user