From c5d7fa667543c145e0ae9ddd77ff987532bafd81 Mon Sep 17 00:00:00 2001 From: Wayne Date: Tue, 27 Jan 2015 14:01:07 -0800 Subject: [PATCH] Support the use of lists in trigger-build builder. Since Jenkins parameterized build trigger buildstep supports comma-separated list of jobs to build, this simply joins a list of jobs specified in JJB yaml on a comma. Change-Id: I0a65f3497d4a68d798ea29c580b6217bbecfe222 --- jenkins_jobs/modules/builders.py | 14 ++++++++++++-- .../fixtures/trigger-builds/project-list.xml | 18 ++++++++++++++++++ .../fixtures/trigger-builds/project-list.yaml | 7 +++++++ 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 tests/builders/fixtures/trigger-builds/project-list.xml create mode 100644 tests/builders/fixtures/trigger-builds/project-list.yaml diff --git a/jenkins_jobs/modules/builders.py b/jenkins_jobs/modules/builders.py index a997871f0..ac0e01fa0 100644 --- a/jenkins_jobs/modules/builders.py +++ b/jenkins_jobs/modules/builders.py @@ -282,7 +282,7 @@ def trigger_builds(parser, xml_parent, data): Requires the Jenkins :jenkins-wiki:`Parameterized Trigger Plugin `. - :arg str project: the Jenkins project to trigger + :arg list project: the Jenkins project to trigger :arg str predefined-parameters: key/value pairs to be passed to the job (optional) :arg list bool-parameters: @@ -355,6 +355,12 @@ def trigger_builds(parser, xml_parent, data): Examples: + Basic usage with yaml list of projects. + + .. literalinclude:: + /../../tests/builders/fixtures/trigger-builds/project-list.yaml + :language: yaml + Basic usage with passing svn revision through. .. literalinclude:: /../../tests/builders/fixtures/trigger-builds001.yaml @@ -515,7 +521,11 @@ def trigger_builds(parser, xml_parent, data): 'ignore-offline-nodes', True)).lower() projects = XML.SubElement(tconfig, 'projects') - projects.text = project_def['project'] + if isinstance(project_def['project'], list): + projects.text = ",".join(project_def['project']) + else: + projects.text = project_def['project'] + condition = XML.SubElement(tconfig, 'condition') condition.text = 'ALWAYS' trigger_with_no_params = XML.SubElement(tconfig, diff --git a/tests/builders/fixtures/trigger-builds/project-list.xml b/tests/builders/fixtures/trigger-builds/project-list.xml new file mode 100644 index 000000000..12d538c97 --- /dev/null +++ b/tests/builders/fixtures/trigger-builds/project-list.xml @@ -0,0 +1,18 @@ + + + + + + + + + + foo,bar,baz + ALWAYS + false + false + + + + + diff --git a/tests/builders/fixtures/trigger-builds/project-list.yaml b/tests/builders/fixtures/trigger-builds/project-list.yaml new file mode 100644 index 000000000..fe37bc270 --- /dev/null +++ b/tests/builders/fixtures/trigger-builds/project-list.yaml @@ -0,0 +1,7 @@ +builders: + - trigger-builds: + - project: + - "foo" + - "bar" + - "baz" + current-parameters: true