diff --git a/jenkins_jobs/modules/publishers.py b/jenkins_jobs/modules/publishers.py index b497df584..57c9a89fe 100644 --- a/jenkins_jobs/modules/publishers.py +++ b/jenkins_jobs/modules/publishers.py @@ -1160,12 +1160,16 @@ def pipeline(parser, xml_parent, data): Requires the Jenkins `Build Pipeline Plugin. <https://wiki.jenkins-ci.org/display/JENKINS/Build+Pipeline+Plugin>`_ - :Parameter: the name of the downstream project + :arg str project: the name of the downstream project + :arg str predefined-parameters: parameters to pass to the other + job (optional) + :arg bool current-parameters: Whether to include the parameters passed + to the current build to the triggered job (optional) - Example:: + Example: + + .. literalinclude:: ../../tests/publishers/fixtures/pipeline002.yaml - publishers: - - pipeline: deploy You can build pipeline jobs that are re-usable in different pipelines by using a :ref:`job-template` to define the pipeline jobs, @@ -1175,11 +1179,27 @@ def pipeline(parser, xml_parent, data): See 'samples/pipeline.yaml' for an example pipeline implementation. """ - if data != '': + if 'project' in data and data['project'] != '': pippub = XML.SubElement(xml_parent, 'au.com.centrumsystems.hudson.plugin.' 'buildpipeline.trigger.BuildPipelineTrigger') - XML.SubElement(pippub, 'downstreamProjectNames').text = data + + configs = XML.SubElement(pippub, 'configs') + + if 'predefined-parameters' in data: + params = XML.SubElement(configs, + 'hudson.plugins.parameterizedtrigger.' + 'PredefinedBuildParameters') + properties = XML.SubElement(params, 'properties') + properties.text = data['predefined-parameters'] + + if ('current-parameters' in data + and data['current-parameters']): + XML.SubElement(configs, + 'hudson.plugins.parameterizedtrigger.' + 'CurrentBuildParameters') + + XML.SubElement(pippub, 'downstreamProjectNames').text = data['project'] def email(parser, xml_parent, data): diff --git a/tests/publishers/fixtures/pipeline001.xml b/tests/publishers/fixtures/pipeline001.xml new file mode 100644 index 000000000..cb448fbb0 --- /dev/null +++ b/tests/publishers/fixtures/pipeline001.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" ?> +<project> + <publishers> + <au.com.centrumsystems.hudson.plugin.buildpipeline.trigger.BuildPipelineTrigger> + <configs/> + <downstreamProjectNames>test_project</downstreamProjectNames> + </au.com.centrumsystems.hudson.plugin.buildpipeline.trigger.BuildPipelineTrigger> + </publishers> +</project> diff --git a/tests/publishers/fixtures/pipeline001.yaml b/tests/publishers/fixtures/pipeline001.yaml new file mode 100644 index 000000000..605ece714 --- /dev/null +++ b/tests/publishers/fixtures/pipeline001.yaml @@ -0,0 +1,3 @@ +publishers: + - pipeline: + project: test_project diff --git a/tests/publishers/fixtures/pipeline002.xml b/tests/publishers/fixtures/pipeline002.xml new file mode 100644 index 000000000..33eca2ab8 --- /dev/null +++ b/tests/publishers/fixtures/pipeline002.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" ?> +<project> + <publishers> + <au.com.centrumsystems.hudson.plugin.buildpipeline.trigger.BuildPipelineTrigger> + <configs> + <hudson.plugins.parameterizedtrigger.PredefinedBuildParameters> + <properties>foo=bar</properties> + </hudson.plugins.parameterizedtrigger.PredefinedBuildParameters> + <hudson.plugins.parameterizedtrigger.CurrentBuildParameters/> + </configs> + <downstreamProjectNames>test_project</downstreamProjectNames> + </au.com.centrumsystems.hudson.plugin.buildpipeline.trigger.BuildPipelineTrigger> + </publishers> +</project> diff --git a/tests/publishers/fixtures/pipeline002.yaml b/tests/publishers/fixtures/pipeline002.yaml new file mode 100644 index 000000000..d28524f93 --- /dev/null +++ b/tests/publishers/fixtures/pipeline002.yaml @@ -0,0 +1,5 @@ +publishers: + - pipeline: + project: test_project + current-parameters: true + predefined-parameters: foo=bar