updated conditional_publisher to support plugin changes
Updated conditional_publisher to support the new XML format in the latest versions (>= 0.13) of the Flexible Publish plugin. Ensured legacy format is still supported for plugin versions < 0.13. Added support for multiple actions per condition with version >= 0.13. Added unit test for multiple actions per condition Change-Id: I4a91d2836ccd079d059b961a7f0b177a17df4093
This commit is contained in:
parent
7447292b57
commit
07f14378b3
@ -31,6 +31,7 @@ import jenkins_jobs.modules.base
|
||||
from jenkins_jobs.modules import hudson_model
|
||||
from jenkins_jobs.errors import JenkinsJobsException
|
||||
import logging
|
||||
import pkg_resources
|
||||
import sys
|
||||
import random
|
||||
|
||||
@ -3993,12 +3994,17 @@ def conditional_publisher(parser, xml_parent, data):
|
||||
/../../tests/publishers/fixtures/conditional-publisher001.yaml
|
||||
:language: yaml
|
||||
|
||||
Multiple Conditional Actions Example:
|
||||
Multiple Conditional Actions Example
|
||||
(includes example of multiple actions per condition which requires
|
||||
v0.13 or higher of the Flexible Publish plugin):
|
||||
|
||||
.. literalinclude:: \
|
||||
/../../tests/publishers/fixtures/conditional-publisher002.yaml
|
||||
/../../tests/publishers/fixtures/conditional-publisher003.yaml
|
||||
:language: yaml
|
||||
|
||||
:download:`Multiple Conditional Actions Example for pre-v0.13 versions
|
||||
<../../tests/publishers/fixtures/conditional-publisher002.yaml>`
|
||||
|
||||
"""
|
||||
def publish_condition(cdata):
|
||||
kind = cdata['condition-kind']
|
||||
@ -4074,8 +4080,9 @@ def conditional_publisher(parser, xml_parent, data):
|
||||
|
||||
def publish_action(parent, action):
|
||||
for edited_node in create_publishers(parser, action):
|
||||
edited_node.set('class', edited_node.tag)
|
||||
edited_node.tag = 'publisher'
|
||||
if not use_publisher_list:
|
||||
edited_node.set('class', edited_node.tag)
|
||||
edited_node.tag = 'publisher'
|
||||
parent.append(edited_node)
|
||||
|
||||
flex_publisher_tag = 'org.jenkins__ci.plugins.flexible__publish.' \
|
||||
@ -4114,14 +4121,27 @@ def conditional_publisher(parser, xml_parent, data):
|
||||
if 'action' in cond_action:
|
||||
actions = cond_action['action']
|
||||
|
||||
# Flexible Publish will overwrite action if more than one is
|
||||
# specified. Limit the action list to one element.
|
||||
if len(actions) is not 1:
|
||||
action_parent = cond_publisher
|
||||
|
||||
plugin_info = \
|
||||
parser.registry.get_plugin_info("Flexible Publish Plugin")
|
||||
version = pkg_resources.parse_version(plugin_info.get('version',
|
||||
'0'))
|
||||
# XML tag changed from publisher to publisherList in v0.13
|
||||
# check the plugin version to determine further operations
|
||||
use_publisher_list = version >= pkg_resources.parse_version("0.13")
|
||||
|
||||
if use_publisher_list:
|
||||
action_parent = XML.SubElement(cond_publisher, 'publisherList')
|
||||
else:
|
||||
# Check the length of actions list for versions prior to 0.13.
|
||||
# Flexible Publish will overwrite action if more than one is
|
||||
# specified. Limit the action list to one element.
|
||||
if len(actions) is not 1:
|
||||
raise JenkinsJobsException("Only one action may be "
|
||||
"specified for each condition.")
|
||||
|
||||
for action in actions:
|
||||
publish_action(cond_publisher, action)
|
||||
publish_action(action_parent, action)
|
||||
else:
|
||||
raise JenkinsJobsException('action must be set for each condition')
|
||||
|
||||
|
@ -24,4 +24,4 @@
|
||||
</publishers>
|
||||
</org.jenkins__ci.plugins.flexible__publish.FlexiblePublisher>
|
||||
</publishers>
|
||||
</project>
|
||||
</project>
|
@ -0,0 +1,3 @@
|
||||
- longName: 'Flexible Publish Plugin'
|
||||
shortName: 'flexible-publish'
|
||||
version: "0.13"
|
23
tests/publishers/fixtures/conditional-publisher003.xml
Normal file
23
tests/publishers/fixtures/conditional-publisher003.xml
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<project>
|
||||
<publishers>
|
||||
<org.jenkins__ci.plugins.flexible__publish.FlexiblePublisher>
|
||||
<publishers>
|
||||
<org.jenkins__ci.plugins.flexible__publish.ConditionalPublisher>
|
||||
<condition class="org.jenkins_ci.plugins.run_condition.core.AlwaysRun"/>
|
||||
<runner class="org.jenkins_ci.plugins.run_condition.BuildStepRunner$RunUnstable"/>
|
||||
<publisherList>
|
||||
<hudson.tasks.ArtifactArchiver>
|
||||
<artifacts>**/**</artifacts>
|
||||
<latestOnly>false</latestOnly>
|
||||
<allowEmptyArchive>true</allowEmptyArchive>
|
||||
</hudson.tasks.ArtifactArchiver>
|
||||
<hudson.tasks.test.AggregatedTestResultPublisher>
|
||||
<includeFailedBuilds>true</includeFailedBuilds>
|
||||
</hudson.tasks.test.AggregatedTestResultPublisher>
|
||||
</publisherList>
|
||||
</org.jenkins__ci.plugins.flexible__publish.ConditionalPublisher>
|
||||
</publishers>
|
||||
</org.jenkins__ci.plugins.flexible__publish.FlexiblePublisher>
|
||||
</publishers>
|
||||
</project>
|
11
tests/publishers/fixtures/conditional-publisher003.yaml
Normal file
11
tests/publishers/fixtures/conditional-publisher003.yaml
Normal file
@ -0,0 +1,11 @@
|
||||
publishers:
|
||||
- conditional-publisher:
|
||||
- condition-kind: always
|
||||
on-evaluation-failure: run-and-mark-unstable
|
||||
action:
|
||||
- archive:
|
||||
artifacts: '**/**'
|
||||
allow-empty: 'true'
|
||||
- aggregate-tests:
|
||||
include-failed-builds: true
|
||||
|
Loading…
Reference in New Issue
Block a user