From 92b7f446f985c7265c9cfeafe886762eb6711fde Mon Sep 17 00:00:00 2001 From: Somay Jain Date: Tue, 21 Jul 2015 17:19:10 +0530 Subject: [PATCH] Support for externaljob project-type for monitoring external jobs Change-Id: I8904725f75d27180d44c55768605db7d67e79586 --- doc/source/definition.rst | 1 + doc/source/project_externaljob.rst | 7 ++++ jenkins_jobs/modules/general.py | 4 +- jenkins_jobs/modules/project_externaljob.py | 44 +++++++++++++++++++++ setup.cfg | 1 + tests/base.py | 5 ++- tests/general/fixtures/project-type005.xml | 9 +++++ tests/general/fixtures/project-type005.yaml | 2 + 8 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 doc/source/project_externaljob.rst create mode 100644 jenkins_jobs/modules/project_externaljob.py create mode 100644 tests/general/fixtures/project-type005.xml create mode 100644 tests/general/fixtures/project-type005.yaml diff --git a/doc/source/definition.rst b/doc/source/definition.rst index a57b248da..77e1d2aac 100644 --- a/doc/source/definition.rst +++ b/doc/source/definition.rst @@ -351,6 +351,7 @@ The bulk of the job definitions come from the following modules. .. toctree:: :maxdepth: 2 + project_externaljob project_flow project_freestyle project_maven diff --git a/doc/source/project_externaljob.rst b/doc/source/project_externaljob.rst new file mode 100644 index 000000000..44282eba1 --- /dev/null +++ b/doc/source/project_externaljob.rst @@ -0,0 +1,7 @@ +.. _project_externaljob: + +ExternalJob Project +=================== + +.. automodule:: project_externaljob + :members: diff --git a/jenkins_jobs/modules/general.py b/jenkins_jobs/modules/general.py index 99fc7c03a..3adabdb72 100644 --- a/jenkins_jobs/modules/general.py +++ b/jenkins_jobs/modules/general.py @@ -21,8 +21,8 @@ Example: :Job Parameters: * **project-type**: - Defaults to "freestyle", but "maven" as well as "multijob" or "flow" - can also be specified. + Defaults to "freestyle", but "maven" as well as "multijob", "flow" or + "externaljob" can also be specified. * **defaults**: Specifies a set of :ref:`defaults` to use for this job, defaults to diff --git a/jenkins_jobs/modules/project_externaljob.py b/jenkins_jobs/modules/project_externaljob.py new file mode 100644 index 000000000..20949650c --- /dev/null +++ b/jenkins_jobs/modules/project_externaljob.py @@ -0,0 +1,44 @@ +# Copyright 2015 Hewlett-Packard Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +""" +The External Job Project module handles creating ExternalJob Jenkins projects. +You may specify ``externaljob`` in the ``project-type`` attribute of the +:ref:`Job` definition. + +This type of job allows you to record the execution of a process run outside +Jenkins, even on a remote machine. This is designed so that you can use +Jenkins as a dashboard of your existing automation system. + +Requires the Jenkins :jenkins-wiki:`External Monitor Job Type Plugin +`. + +Example: + + .. literalinclude:: /../../tests/general/fixtures/project-type005.yaml + +""" + + +import xml.etree.ElementTree as XML +import jenkins_jobs.modules.base + + +class ExternalJob(jenkins_jobs.modules.base.Base): + sequence = 0 + + def root_xml(self, data): + xml_parent = XML.Element('hudson.model.ExternalJob') + return xml_parent diff --git a/setup.cfg b/setup.cfg index 37ec916fc..86476c42c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -38,6 +38,7 @@ warnerrors = True console_scripts = jenkins-jobs=jenkins_jobs.cmd:main jenkins_jobs.projects = + externaljob=jenkins_jobs.modules.project_externaljob:ExternalJob flow=jenkins_jobs.modules.project_flow:Flow freestyle=jenkins_jobs.modules.project_freestyle:Freestyle matrix=jenkins_jobs.modules.project_matrix:Matrix diff --git a/tests/base.py b/tests/base.py index 517cfc980..9b75414fa 100644 --- a/tests/base.py +++ b/tests/base.py @@ -42,7 +42,8 @@ from jenkins_jobs.xml_config import XmlJob from jenkins_jobs.modules import (project_flow, project_matrix, project_maven, - project_multijob) + project_multijob, + project_externaljob) def get_scenarios(fixtures_path, in_ext='yaml', out_ext='xml', @@ -140,6 +141,8 @@ class BaseTestCase(object): project = project_flow.Flow(None) elif (yaml_content['project-type'] == "multijob"): project = project_multijob.MultiJob(None) + elif (yaml_content['project-type'] == "externaljob"): + project = project_externaljob.ExternalJob(None) if project: xml_project = project.root_xml(yaml_content) diff --git a/tests/general/fixtures/project-type005.xml b/tests/general/fixtures/project-type005.xml new file mode 100644 index 000000000..cfa5ecf90 --- /dev/null +++ b/tests/general/fixtures/project-type005.xml @@ -0,0 +1,9 @@ + + + + false + false + false + false + true + \ No newline at end of file diff --git a/tests/general/fixtures/project-type005.yaml b/tests/general/fixtures/project-type005.yaml new file mode 100644 index 000000000..6fb0215b6 --- /dev/null +++ b/tests/general/fixtures/project-type005.yaml @@ -0,0 +1,2 @@ +name: openstack-infra +project-type: externaljob \ No newline at end of file