summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--jenkins_jobs/builder.py2
-rw-r--r--jenkins_jobs/formatter.py24
-rw-r--r--jenkins_jobs/local_yaml.py19
-rw-r--r--jenkins_jobs/modules/publishers.py5
-rw-r--r--jenkins_jobs/modules/triggers.py34
-rw-r--r--jenkins_jobs/modules/wrappers.py3
-rw-r--r--jenkins_jobs/parser.py10
-rw-r--r--tests/publishers/fixtures/workspace-cleanup-full.xml1
-rw-r--r--tests/publishers/fixtures/workspace-cleanup-full.yaml1
-rw-r--r--tests/publishers/fixtures/workspace-cleanup-minimal.xml1
-rw-r--r--tests/triggers/fixtures/rabbitmq-filters.xml19
-rw-r--r--tests/triggers/fixtures/rabbitmq-filters.yaml8
-rw-r--r--tests/wrappers/fixtures/workspace-cleanup-full.xml1
-rw-r--r--tests/wrappers/fixtures/workspace-cleanup-full.yaml1
-rw-r--r--tests/wrappers/fixtures/workspace-cleanup-min.xml1
-rw-r--r--tests/yamlparser/fixtures/jinja-as-yaml-include01.xml31
-rw-r--r--tests/yamlparser/fixtures/jinja-as-yaml-include01.yaml7
-rw-r--r--tests/yamlparser/fixtures/jinja-as-yaml-include01.yaml.inc3
18 files changed, 78 insertions, 93 deletions
diff --git a/jenkins_jobs/builder.py b/jenkins_jobs/builder.py
index 5d7bbe34..32c0c39b 100644
--- a/jenkins_jobs/builder.py
+++ b/jenkins_jobs/builder.py
@@ -181,7 +181,7 @@ class JenkinsManager(object):
def is_managed(self, job_name):
xml = self.jenkins.get_job_config(job_name)
try:
- out = XML.fromstring(xml)
+ out = XML.fromstring(xml.encode('utf-8'))
description = out.find(".//description").text
return description.endswith(MAGIC_MANAGE_STRING)
except (TypeError, AttributeError):
diff --git a/jenkins_jobs/formatter.py b/jenkins_jobs/formatter.py
index 5bd1b710..bd2576b9 100644
--- a/jenkins_jobs/formatter.py
+++ b/jenkins_jobs/formatter.py
@@ -26,7 +26,7 @@ from jenkins_jobs.local_yaml import CustomLoader
logger = logging.getLogger(__name__)
-def deep_format(obj, paramdict, allow_empty=False, template=True):
+def deep_format(obj, paramdict, allow_empty=False):
"""Apply the paramdict via str.format() to all string objects found within
the supplied obj. Lists and dicts are traversed recursively."""
# YAML serialisation was originally used to achieve this, but that places
@@ -50,26 +50,13 @@ def deep_format(obj, paramdict, allow_empty=False, template=True):
elif isinstance(obj, list):
ret = type(obj)()
for item in obj:
- ret.append(deep_format(item, paramdict,
- allow_empty=allow_empty,
- template=template))
+ ret.append(deep_format(item, paramdict, allow_empty))
elif isinstance(obj, dict):
ret = type(obj)()
for item in obj:
try:
- # deep_formatting dsl when not a job-template is not necessary
- # as it will most likely result in keyerror due to trying
- # to substitute values inside the dsl that do not exist.
- if item not in ['dsl'] or template:
- ret[CustomFormatter(allow_empty).format(item,
- **paramdict)] = \
- deep_format(obj[item], paramdict,
- allow_empty=allow_empty,
- template=template)
- else:
- ret[CustomFormatter(allow_empty).format(item,
- **paramdict)] = \
- obj[item]
+ ret[CustomFormatter(allow_empty).format(item, **paramdict)] = \
+ deep_format(obj[item], paramdict, allow_empty)
except KeyError as exc:
missing_key = exc.args[0]
desc = "%s parameter missing to format %s\nGiven:\n%s" % (
@@ -85,8 +72,7 @@ def deep_format(obj, paramdict, allow_empty=False, template=True):
if isinstance(ret, CustomLoader):
# If we have a CustomLoader here, we've lazily-loaded a template;
# attempt to format it.
- ret = deep_format(ret, paramdict, allow_empty=allow_empty,
- template=template)
+ ret = deep_format(ret, paramdict, allow_empty=allow_empty)
return ret
diff --git a/jenkins_jobs/local_yaml.py b/jenkins_jobs/local_yaml.py
index 75d1c5c6..213d8a7a 100644
--- a/jenkins_jobs/local_yaml.py
+++ b/jenkins_jobs/local_yaml.py
@@ -491,17 +491,6 @@ class YamlIncludeJinja2(YamlIncludeRaw):
return Jinja2Loader(contents, loader.search_path)
-class YamlIncludeJinja2AsYaml(YamlIncludeJinja2):
- yaml_tag = u'!include-jinja2-as-yaml:'
-
- @classmethod
- def _from_file(cls, loader, node):
- contents = cls._open_file(loader, node)
- if isinstance(contents, LazyLoader):
- return contents
- return Jinja2LoaderAsYaml(contents, loader.search_path)
-
-
class DeprecatedTag(BaseYAMLObject):
@classmethod
@@ -548,14 +537,6 @@ class Jinja2Loader(CustomLoader):
return self._template.render(kwargs)
-class Jinja2LoaderAsYaml(Jinja2Loader):
- """A loader for Jinja2-templated files that renders yaml."""
-
- def format(self, **kwargs):
- raw_yaml = super(Jinja2LoaderAsYaml, self).format(**kwargs)
- return yaml.load(raw_yaml)
-
-
class CustomLoaderCollection(object):
"""Helper class to format a collection of CustomLoader objects"""
def __init__(self, sequence):
diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py
index b8cdaff8..29c3ea4e 100644
--- a/jenkins_jobs/modules/publishers.py
+++ b/jenkins_jobs/modules/publishers.py
@@ -3521,6 +3521,8 @@ def workspace_cleanup(registry, xml_parent, data):
:arg bool clean-parent: Cleanup matrix parent workspace (default false)
:arg str external-deletion-command: external deletion command to run
against files and directories
+ :arg bool disable-deferred-wipeout: Disable improved deferred wipeout
+ method (default false)
Minimal Example:
@@ -3554,7 +3556,8 @@ def workspace_cleanup(registry, xml_parent, data):
mappings = [
('dirmatch', 'deleteDirs', False),
('clean-parent', 'cleanupMatrixParent', False),
- ('external-deletion-command', 'externalDelete', '')
+ ('external-deletion-command', 'externalDelete', ''),
+ ('disable-deferred-wipeout', 'disableDeferredWipeout', False),
]
helpers.convert_mapping_to_xml(p, data, mappings, fail_required=True)
diff --git a/jenkins_jobs/modules/triggers.py b/jenkins_jobs/modules/triggers.py
index f128a354..fcd93390 100644
--- a/jenkins_jobs/modules/triggers.py
+++ b/jenkins_jobs/modules/triggers.py
@@ -846,6 +846,8 @@ def jms_messaging(registry, xml_parent, data):
Requires the Jenkins :jenkins-wiki:`JMS Messaging Plugin
<JMS+Messaging+Plugin>`.
+ :arg str override-topic: If you need to override the default topic.
+ (default '')
:arg str selector: The JSON or YAML formatted text that conforms to
the schema for defining the various OpenShift resources. (default '')
note: topic needs to be in double quotes
@@ -873,6 +875,11 @@ def jms_messaging(registry, xml_parent, data):
jmsm = XML.SubElement(xml_parent,
namespace + 'CIBuildTrigger')
+ if 'override-topic' in data:
+ overrides = XML.SubElement(jmsm, 'overrides')
+ XML.SubElement(overrides,
+ 'topic').text = str(data['override-topic'])
+
mapping = [
# option, xml name, default value
("spec", 'spec', ''),
@@ -1915,17 +1922,40 @@ def rabbitmq(registry, xml_parent, data):
<RabbitMQ+Build+Trigger+Plugin>`.
:arg str token: the build token expected in the message queue (required)
+ :arg list filters: list of filters to apply (optional)
+
+ :Filter:
+ * **field** (`str`) - Some field in message (required)
+ * **value** (`str`) - value of specified field (required)
Example:
.. literalinclude:: /../../tests/triggers/fixtures/rabbitmq.yaml
:language: yaml
+
+ Example with filters:
+
+ .. literalinclude:: /../../tests/triggers/fixtures/rabbitmq-filters.yaml
+ :language: yaml
"""
+ rabbitmq_prefix = 'org.jenkinsci.plugins.rabbitmqbuildtrigger.'
rabbitmq = XML.SubElement(
xml_parent,
- 'org.jenkinsci.plugins.rabbitmqbuildtrigger.'
- 'RemoteBuildTrigger')
+ rabbitmq_prefix + 'RemoteBuildTrigger')
+ filters = data.get('filters', [])
+ filter_mapping = [
+ ('field', 'field', None),
+ ('value', 'value', None),
+ ]
+ if filters:
+ filters_tag = XML.SubElement(rabbitmq, 'filters')
+ for filter_data in filters:
+ filter_tag = XML.SubElement(
+ filters_tag,
+ rabbitmq_prefix + 'Filter')
+ helpers.convert_mapping_to_xml(
+ filter_tag, filter_data, filter_mapping, fail_required=True)
mapping = [
('', 'spec', ''),
('token', 'remoteBuildToken', None),
diff --git a/jenkins_jobs/modules/wrappers.py b/jenkins_jobs/modules/wrappers.py
index 16b2d86b..ab5dc2b3 100644
--- a/jenkins_jobs/modules/wrappers.py
+++ b/jenkins_jobs/modules/wrappers.py
@@ -767,6 +767,8 @@ def workspace_cleanup(registry, xml_parent, data):
determine whether to actually clean up
:arg str external-deletion-command: external deletion command to run
against files and directories
+ :arg bool disable-deferred-wipeout: Disable improved deferred wipeout
+ method (default false)
Full Example:
@@ -808,6 +810,7 @@ def workspace_cleanup(registry, xml_parent, data):
("dirmatch", 'deleteDirs', False),
('check-parameter', 'cleanupParameter', ''),
('external-deletion-command', 'externalDelete', ''),
+ ('disable-deferred-wipeout', 'disableDeferredWipeout', False),
]
helpers.convert_mapping_to_xml(p, data, mapping, fail_required=True)
diff --git a/jenkins_jobs/parser.py b/jenkins_jobs/parser.py
index e8549c8f..667ce426 100644
--- a/jenkins_jobs/parser.py
+++ b/jenkins_jobs/parser.py
@@ -243,16 +243,6 @@ class YamlParser(object):
if jobs_glob and not matches(job['name'], jobs_glob):
logger.debug("Ignoring job {0}".format(job['name']))
continue
-
- # Attempt to format all parts of the job definition as they might
- # be using custom loaders.
- try:
- job = deep_format(job, job, template=False)
- except Exception:
- logging.error(
- "Failure formatting job '%s' with itself", job)
- raise
-
logger.debug("Expanding job '{0}'".format(job['name']))
self._formatDescription(job)
self.jobs.append(job)
diff --git a/tests/publishers/fixtures/workspace-cleanup-full.xml b/tests/publishers/fixtures/workspace-cleanup-full.xml
index d5563863..ebe438e9 100644
--- a/tests/publishers/fixtures/workspace-cleanup-full.xml
+++ b/tests/publishers/fixtures/workspace-cleanup-full.xml
@@ -15,6 +15,7 @@
<deleteDirs>true</deleteDirs>
<cleanupMatrixParent>true</cleanupMatrixParent>
<externalDelete>command</externalDelete>
+ <disableDeferredWipeout>true</disableDeferredWipeout>
<cleanWhenSuccess>false</cleanWhenSuccess>
<cleanWhenUnstable>false</cleanWhenUnstable>
<cleanWhenFailure>false</cleanWhenFailure>
diff --git a/tests/publishers/fixtures/workspace-cleanup-full.yaml b/tests/publishers/fixtures/workspace-cleanup-full.yaml
index 1ea41495..0f5f5e52 100644
--- a/tests/publishers/fixtures/workspace-cleanup-full.yaml
+++ b/tests/publishers/fixtures/workspace-cleanup-full.yaml
@@ -14,3 +14,4 @@ publishers:
fail-build: false
clean-parent: true
external-deletion-command: 'command'
+ disable-deferred-wipeout: true
diff --git a/tests/publishers/fixtures/workspace-cleanup-minimal.xml b/tests/publishers/fixtures/workspace-cleanup-minimal.xml
index 36f0e03e..d264147d 100644
--- a/tests/publishers/fixtures/workspace-cleanup-minimal.xml
+++ b/tests/publishers/fixtures/workspace-cleanup-minimal.xml
@@ -5,6 +5,7 @@
<deleteDirs>false</deleteDirs>
<cleanupMatrixParent>false</cleanupMatrixParent>
<externalDelete/>
+ <disableDeferredWipeout>false</disableDeferredWipeout>
<cleanWhenSuccess>true</cleanWhenSuccess>
<cleanWhenUnstable>true</cleanWhenUnstable>
<cleanWhenFailure>true</cleanWhenFailure>
diff --git a/tests/triggers/fixtures/rabbitmq-filters.xml b/tests/triggers/fixtures/rabbitmq-filters.xml
new file mode 100644
index 00000000..db1c0bff
--- /dev/null
+++ b/tests/triggers/fixtures/rabbitmq-filters.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<project>
+ <triggers class="vector">
+ <org.jenkinsci.plugins.rabbitmqbuildtrigger.RemoteBuildTrigger>
+ <filters>
+ <org.jenkinsci.plugins.rabbitmqbuildtrigger.Filter>
+ <field>field1</field>
+ <value>value1</value>
+ </org.jenkinsci.plugins.rabbitmqbuildtrigger.Filter>
+ <org.jenkinsci.plugins.rabbitmqbuildtrigger.Filter>
+ <field>field2</field>
+ <value>value2</value>
+ </org.jenkinsci.plugins.rabbitmqbuildtrigger.Filter>
+ </filters>
+ <spec/>
+ <remoteBuildToken>build_trigger_token</remoteBuildToken>
+ </org.jenkinsci.plugins.rabbitmqbuildtrigger.RemoteBuildTrigger>
+ </triggers>
+</project>
diff --git a/tests/triggers/fixtures/rabbitmq-filters.yaml b/tests/triggers/fixtures/rabbitmq-filters.yaml
new file mode 100644
index 00000000..bfcdfa99
--- /dev/null
+++ b/tests/triggers/fixtures/rabbitmq-filters.yaml
@@ -0,0 +1,8 @@
+triggers:
+ - rabbitmq:
+ token: 'build_trigger_token'
+ filters:
+ - field: 'field1'
+ value: 'value1'
+ - field: 'field2'
+ value: 'value2'
diff --git a/tests/wrappers/fixtures/workspace-cleanup-full.xml b/tests/wrappers/fixtures/workspace-cleanup-full.xml
index 06b9e11b..22f72f23 100644
--- a/tests/wrappers/fixtures/workspace-cleanup-full.xml
+++ b/tests/wrappers/fixtures/workspace-cleanup-full.xml
@@ -15,6 +15,7 @@
<deleteDirs>true</deleteDirs>
<cleanupParameter>DO_WS_CLEANUP</cleanupParameter>
<externalDelete>shred -u %s</externalDelete>
+ <disableDeferredWipeout>true</disableDeferredWipeout>
</hudson.plugins.ws__cleanup.PreBuildCleanup>
</buildWrappers>
</project>
diff --git a/tests/wrappers/fixtures/workspace-cleanup-full.yaml b/tests/wrappers/fixtures/workspace-cleanup-full.yaml
index 4ec97cbd..94b66223 100644
--- a/tests/wrappers/fixtures/workspace-cleanup-full.yaml
+++ b/tests/wrappers/fixtures/workspace-cleanup-full.yaml
@@ -7,3 +7,4 @@ wrappers:
dirmatch: true
check-parameter: "DO_WS_CLEANUP"
external-deletion-command: "shred -u %s"
+ disable-deferred-wipeout: true
diff --git a/tests/wrappers/fixtures/workspace-cleanup-min.xml b/tests/wrappers/fixtures/workspace-cleanup-min.xml
index 309a65be..eaecd5d8 100644
--- a/tests/wrappers/fixtures/workspace-cleanup-min.xml
+++ b/tests/wrappers/fixtures/workspace-cleanup-min.xml
@@ -5,6 +5,7 @@
<deleteDirs>false</deleteDirs>
<cleanupParameter/>
<externalDelete/>
+ <disableDeferredWipeout>false</disableDeferredWipeout>
</hudson.plugins.ws__cleanup.PreBuildCleanup>
</buildWrappers>
</project>
diff --git a/tests/yamlparser/fixtures/jinja-as-yaml-include01.xml b/tests/yamlparser/fixtures/jinja-as-yaml-include01.xml
deleted file mode 100644
index 732bb2c4..00000000
--- a/tests/yamlparser/fixtures/jinja-as-yaml-include01.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<project>
- <actions/>
- <description>&lt;!-- Managed by Jenkins Job Builder --&gt;</description>
- <keepDependencies>false</keepDependencies>
- <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
- <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
- <concurrentBuild>false</concurrentBuild>
- <canRoam>true</canRoam>
- <properties>
- <hudson.model.ParametersDefinitionProperty>
- <parameterDefinitions>
- <hudson.model.ChoiceParameterDefinition>
- <name>TEST_CHOICE</name>
- <description/>
- <choices class="java.util.Arrays$ArrayList">
- <a class="string-array">
- <string>a</string>
- <string>b</string>
- <string>c</string>
- </a>
- </choices>
- </hudson.model.ChoiceParameterDefinition>
- </parameterDefinitions>
- </hudson.model.ParametersDefinitionProperty>
- </properties>
- <scm class="hudson.scm.NullSCM"/>
- <builders/>
- <publishers/>
- <buildWrappers/>
-</project>
diff --git a/tests/yamlparser/fixtures/jinja-as-yaml-include01.yaml b/tests/yamlparser/fixtures/jinja-as-yaml-include01.yaml
deleted file mode 100644
index 2ea430f0..00000000
--- a/tests/yamlparser/fixtures/jinja-as-yaml-include01.yaml
+++ /dev/null
@@ -1,7 +0,0 @@
-- job:
- name: test-job-as-yaml
- parameters:
- - choice:
- name: TEST_CHOICE
- choices:
- !include-jinja2-as-yaml: jinja-as-yaml-include01.yaml.inc
diff --git a/tests/yamlparser/fixtures/jinja-as-yaml-include01.yaml.inc b/tests/yamlparser/fixtures/jinja-as-yaml-include01.yaml.inc
deleted file mode 100644
index c1c3c8b3..00000000
--- a/tests/yamlparser/fixtures/jinja-as-yaml-include01.yaml.inc
+++ /dev/null
@@ -1,3 +0,0 @@
-{% for item in ['a', 'b', 'c'] %}
-- {{ item }}
-{% endfor -%}