diff --git a/jenkins_jobs/modules/builders.py b/jenkins_jobs/modules/builders.py index 0f101dba8..265874134 100644 --- a/jenkins_jobs/modules/builders.py +++ b/jenkins_jobs/modules/builders.py @@ -514,6 +514,106 @@ def maven_target(parser, xml_parent, data): 'class': 'jenkins.mvn.DefaultGlobalSettingsProvider'}) +def multijob(parser, xml_parent, data): + """yaml: multijob + Define a multijob phase. Requires the Jenkins `Multijob Plugin. + `_ + + This builder may only be used in \ + :py:class:`jenkins_jobs.modules.project_multijob.MultiJob` projects. + + :arg str name: MultiJob phase name + :arg str condition: when to trigger the other job (default 'SUCCESSFUL') + :arg list projects: list of projects to include in the MultiJob phase + + :Project: * **name** (`str`) -- Project name + * **current-parameters** (`bool`) -- Pass current build + parameters to the other job (default false) + * **git-revision** (`bool`) -- Pass current git-revision + to the other job (default false) + * **property-file** (`str`) -- Pass properties from file + to the other job (optional) + * **predefined-parameters** (`str`) -- Pass predefined + parameters to the other job (optional) + + Example:: + + builders: + - multijob: + name: PhaseOne + condition: SUCCESSFUL + projects: + - name: PhaseOneJobA + current-parameters: true + git-revision: true + - name: PhaseOneJobB + current-parameters: true + property-file: build.props + - multijob: + name: PhaseTwo + condition: UNSTABLE + projects: + - name: PhaseTwoJobA + current-parameters: true + predefined-parameters: foo=bar + - name: PhaseTwoJobB + current-parameters: false + + + """ + builder = XML.SubElement(xml_parent, 'com.tikal.jenkins.plugins.multijob.' + 'MultiJobBuilder') + XML.SubElement(builder, 'phaseName').text = data['name'] + + condition = data.get('condition', 'SUCCESSFUL') + XML.SubElement(builder, 'continuationCondition').text = condition + + phaseJobs = XML.SubElement(builder, 'phaseJobs') + + for project in data.get('projects', []): + phaseJob = XML.SubElement(phaseJobs, 'com.tikal.jenkins.plugins.' + 'multijob.PhaseJobsConfig') + + XML.SubElement(phaseJob, 'jobName').text = project['name'] + + # Pass through the current build params + currParams = str(project.get('current-parameters', False)).lower() + XML.SubElement(phaseJob, 'currParams').text = currParams + + # Pass through other params + configs = XML.SubElement(phaseJob, 'configs') + + # Git Revision + if project.get('git-revision', False): + param = XML.SubElement(configs, + 'hudson.plugins.git.' + 'GitRevisionBuildParameters') + combine = XML.SubElement(param, 'combineQueuedCommits') + combine.text = 'false' + + # Properties File + properties_file = project.get('property-file', False) + if properties_file: + param = XML.SubElement(configs, + 'hudson.plugins.parameterizedtrigger.' + 'FileBuildParameters') + + propertiesFile = XML.SubElement(param, 'propertiesFile') + propertiesFile.text = properties_file + + failOnMissing = XML.SubElement(param, 'failTriggerOnMissing') + failOnMissing.text = 'true' + + # Predefined Parameters + predefined_parameters = project.get('predefined-parameters', False) + if predefined_parameters: + param = XML.SubElement(configs, + 'hudson.plugins.parameterizedtrigger.' + 'PredefinedBuildParameters') + properties = XML.SubElement(param, 'properties') + properties.text = predefined_parameters + + class Builders(jenkins_jobs.modules.base.Base): sequence = 60 diff --git a/jenkins_jobs/modules/project_multijob.py b/jenkins_jobs/modules/project_multijob.py new file mode 100644 index 000000000..ed1f6c783 --- /dev/null +++ b/jenkins_jobs/modules/project_multijob.py @@ -0,0 +1,65 @@ +# Copyright 2013 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 MultiJob Project module handles creating MultiJob Jenkins projects. +You may specify ``multijob`` in the ``project-type`` attribute of +the :ref:`Job` definition. + +This project type may use :py:func:`jenkins_jobs.modules.builders.multijob` \ +builders. + +Requires the Jenkins `Multijob Plugin. +`_ + +Example:: + + job: + name: test_job + project-type: multijob + builders: + - multijob: + name: PhaseOne + condition: SUCCESSFUL + projects: + - name: PhaseOneJobA + current-parameters: true + git-revision: true + - name: PhaseOneJobB + current-parameters: true + property-file: build.props + - multijob: + name: PhaseTwo + condition: UNSTABLE + projects: + - name: PhaseTwoJobA + current-parameters: true + predefined-parameters: foo=bar + - name: PhaseTwoJobB + current-parameters: false +""" + + +import xml.etree.ElementTree as XML +import jenkins_jobs.modules.base + + +class MultiJob(jenkins_jobs.modules.base.Base): + sequence = 0 + + def root_xml(self, data): + xml_parent = XML.Element('com.tikal.jenkins.plugins.multijob.' + 'MultiJobProject') + return xml_parent diff --git a/setup.py b/setup.py index a3f670af4..d979fc93c 100644 --- a/setup.py +++ b/setup.py @@ -52,6 +52,7 @@ setuptools.setup( 'freestyle=jenkins_jobs.modules.project_freestyle:Freestyle', 'maven=jenkins_jobs.modules.project_maven:Maven', 'matrix=jenkins_jobs.modules.project_matrix:Matrix', + 'multijob=jenkins_jobs.modules.project_multijob:MultiJob', ], 'jenkins_jobs.builders': [ 'shell=jenkins_jobs.modules.builders:shell', @@ -65,6 +66,7 @@ setuptools.setup( 'gradle=jenkins_jobs.modules.builders:gradle', 'batch=jenkins_jobs.modules.builders:batch', 'maven-target=jenkins_jobs.modules.builders:maven_target', + 'multijob=jenkins_jobs.modules.builders:multijob', ], 'jenkins_jobs.reporters': [ 'email=jenkins_jobs.modules.reporters:email',