diff --git a/jenkins_jobs/modules/builders.py b/jenkins_jobs/modules/builders.py index 294f7df66..6c249d3f2 100644 --- a/jenkins_jobs/modules/builders.py +++ b/jenkins_jobs/modules/builders.py @@ -40,6 +40,8 @@ import logging import sys import xml.etree.ElementTree as XML +import six + from jenkins_jobs.errors import is_sequence from jenkins_jobs.errors import InvalidAttributeError from jenkins_jobs.errors import JenkinsJobsException @@ -65,16 +67,36 @@ def shell(registry, xml_parent, data): """yaml: shell Execute a shell command. + There are two ways of configuring the builder, with a plain string to + execute: + :arg str parameter: the shell command to execute + Or with a mapping that allows other parameters to be passed: + + :arg str command: the shell command to execute + :arg int unstable-return: + the shell exit code to interpret as an unstable build result + Example: .. literalinclude:: /../../tests/builders/fixtures/shell.yaml :language: yaml + .. literalinclude:: + /../../tests/builders/fixtures/shell-unstable-return.yaml + :language: yaml """ shell = XML.SubElement(xml_parent, 'hudson.tasks.Shell') - XML.SubElement(shell, 'command').text = data + if isinstance(data, six.string_types): + XML.SubElement(shell, 'command').text = data + else: + mappings = [ + ('command', 'command', None), + ('unstable-return', 'unstableReturn', 0), + + ] + convert_mapping_to_xml(shell, data, mappings, fail_required=True) def python(registry, xml_parent, data): diff --git a/tests/builders/fixtures/shell-mapping.xml b/tests/builders/fixtures/shell-mapping.xml new file mode 100644 index 000000000..ed9383959 --- /dev/null +++ b/tests/builders/fixtures/shell-mapping.xml @@ -0,0 +1,9 @@ + + + + + make test + 0 + + + diff --git a/tests/builders/fixtures/shell-mapping.yaml b/tests/builders/fixtures/shell-mapping.yaml new file mode 100644 index 000000000..a949efe08 --- /dev/null +++ b/tests/builders/fixtures/shell-mapping.yaml @@ -0,0 +1,3 @@ +builders: + - shell: + command: "make test" diff --git a/tests/builders/fixtures/shell-unstable-return.xml b/tests/builders/fixtures/shell-unstable-return.xml new file mode 100644 index 000000000..8daf8f492 --- /dev/null +++ b/tests/builders/fixtures/shell-unstable-return.xml @@ -0,0 +1,9 @@ + + + + + make test + 3 + + + diff --git a/tests/builders/fixtures/shell-unstable-return.yaml b/tests/builders/fixtures/shell-unstable-return.yaml new file mode 100644 index 000000000..6db7c1183 --- /dev/null +++ b/tests/builders/fixtures/shell-unstable-return.yaml @@ -0,0 +1,4 @@ +builders: + - shell: + command: "make test" + unstable-return: 3