Builders: conditional-step fix
When multiple steps are used, the condition has the wrong kind of conditional and is always "Always". Add test that exercise multiple steps with a And condition. Also add a dummy test when multiple steps are listed. Fix https://storyboard.openstack.org/#!/story/2000594 Change-Id: I4802bec9db407a09b23eea7e31235136d8bb72c2
This commit is contained in:
parent
a02b20cd36
commit
ad5ae3e2d6
@ -1448,8 +1448,11 @@ def conditional_step(registry, xml_parent, data):
|
||||
(required)
|
||||
================== ====================================================
|
||||
|
||||
Example:
|
||||
Examples:
|
||||
|
||||
.. literalinclude::
|
||||
/../../tests/builders/fixtures/conditional-step-multiple-steps.yaml
|
||||
:language: yaml
|
||||
.. literalinclude::
|
||||
/../../tests/builders/fixtures/conditional-step-success-failure.yaml
|
||||
:language: yaml
|
||||
@ -1475,7 +1478,7 @@ def conditional_step(registry, xml_parent, data):
|
||||
/../../tests/builders/fixtures/conditional-step-and.yaml
|
||||
:language: yaml
|
||||
"""
|
||||
def build_condition(cdata, cond_root_tag):
|
||||
def build_condition(cdata, cond_root_tag, condition_tag):
|
||||
kind = cdata['condition-kind']
|
||||
ctag = XML.SubElement(cond_root_tag, condition_tag)
|
||||
core_prefix = 'org.jenkins_ci.plugins.run_condition.core.'
|
||||
@ -1656,7 +1659,7 @@ def conditional_step(registry, xml_parent, data):
|
||||
notcondition = cdata['condition-operand']
|
||||
except KeyError:
|
||||
raise MissingAttributeError('condition-operand')
|
||||
build_condition(notcondition, ctag)
|
||||
build_condition(notcondition, ctag, "condition")
|
||||
elif kind == "and" or "or":
|
||||
if kind == "and":
|
||||
ctag.set('class', logic_prefix + 'And')
|
||||
@ -1672,7 +1675,8 @@ def conditional_step(registry, xml_parent, data):
|
||||
for condition in conditions_list:
|
||||
conditions_container_tag = XML.SubElement(conditions_tag,
|
||||
container_tag_text)
|
||||
build_condition(condition, conditions_container_tag)
|
||||
build_condition(condition, conditions_container_tag,
|
||||
"condition")
|
||||
|
||||
def build_step(parent, step):
|
||||
for edited_node in create_builders(registry, step):
|
||||
@ -1697,7 +1701,7 @@ def conditional_step(registry, xml_parent, data):
|
||||
steps_parent = root_tag
|
||||
condition_tag = "condition"
|
||||
|
||||
build_condition(data, root_tag)
|
||||
build_condition(data, root_tag, condition_tag)
|
||||
evaluation_classes_pkg = 'org.jenkins_ci.plugins.run_condition'
|
||||
evaluation_classes = {
|
||||
'fail': evaluation_classes_pkg + '.BuildStepRunner$Fail',
|
||||
|
@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<builders>
|
||||
<org.jenkinsci.plugins.conditionalbuildstep.ConditionalBuilder>
|
||||
<conditionalbuilders>
|
||||
<hudson.tasks.Shell>
|
||||
<command>sl</command>
|
||||
</hudson.tasks.Shell>
|
||||
<hudson.tasks.Shell>
|
||||
<command>ls</command>
|
||||
</hudson.tasks.Shell>
|
||||
</conditionalbuilders>
|
||||
<runCondition class="org.jenkins_ci.plugins.run_condition.logic.And">
|
||||
<conditions>
|
||||
<org.jenkins__ci.plugins.run__condition.logic.ConditionContainer>
|
||||
<condition class="org.jenkins_ci.plugins.run_condition.core.ExpressionCondition">
|
||||
<expression>*abc*</expression>
|
||||
<label>dabcddabc</label>
|
||||
</condition>
|
||||
</org.jenkins__ci.plugins.run__condition.logic.ConditionContainer>
|
||||
<org.jenkins__ci.plugins.run__condition.logic.ConditionContainer>
|
||||
<condition class="org.jenkins_ci.plugins.run_condition.core.TimeCondition">
|
||||
<earliestHours>2</earliestHours>
|
||||
<earliestMinutes>0</earliestMinutes>
|
||||
<latestHours>23</latestHours>
|
||||
<latestMinutes>40</latestMinutes>
|
||||
<useBuildTime>true</useBuildTime>
|
||||
</condition>
|
||||
</org.jenkins__ci.plugins.run__condition.logic.ConditionContainer>
|
||||
</conditions>
|
||||
</runCondition>
|
||||
<runner class="org.jenkins_ci.plugins.run_condition.BuildStepRunner$Fail"/>
|
||||
</org.jenkinsci.plugins.conditionalbuildstep.ConditionalBuilder>
|
||||
</builders>
|
||||
</project>
|
@ -0,0 +1,16 @@
|
||||
builders:
|
||||
- conditional-step:
|
||||
condition-kind: and
|
||||
condition-operands:
|
||||
- condition-kind: regex-match
|
||||
regex: "*abc*"
|
||||
label: "dabcddabc"
|
||||
- condition-kind: time
|
||||
earliest-hour: "2"
|
||||
earliest-min: "0"
|
||||
latest-hour: "23"
|
||||
latest-min: "40"
|
||||
use-build-time: true
|
||||
steps:
|
||||
- shell: "sl"
|
||||
- shell: "ls"
|
17
tests/builders/fixtures/conditional-step-multiple-steps.xml
Normal file
17
tests/builders/fixtures/conditional-step-multiple-steps.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<builders>
|
||||
<org.jenkinsci.plugins.conditionalbuildstep.ConditionalBuilder>
|
||||
<conditionalbuilders>
|
||||
<hudson.tasks.Shell>
|
||||
<command>first command</command>
|
||||
</hudson.tasks.Shell>
|
||||
<hudson.tasks.Shell>
|
||||
<command>second command</command>
|
||||
</hudson.tasks.Shell>
|
||||
</conditionalbuilders>
|
||||
<runCondition class="org.jenkins_ci.plugins.run_condition.core.AlwaysRun"/>
|
||||
<runner class="org.jenkins_ci.plugins.run_condition.BuildStepRunner$Fail"/>
|
||||
</org.jenkinsci.plugins.conditionalbuildstep.ConditionalBuilder>
|
||||
</builders>
|
||||
</project>
|
@ -0,0 +1,7 @@
|
||||
builders:
|
||||
- conditional-step:
|
||||
condition-kind: always
|
||||
steps:
|
||||
- shell: 'first command'
|
||||
- shell: 'second command'
|
||||
|
Loading…
x
Reference in New Issue
Block a user