From eb210845e43bd8a788f4f604721d23b4722c3032 Mon Sep 17 00:00:00 2001 From: "william.soula" Date: Tue, 27 Nov 2012 10:23:10 -0600 Subject: [PATCH] Adding ability to specify the JDK to use. This change moves the top level config from builder.py into a separate file called general.py. This change also moves the assigned node work as well as the log rotator work into the general.py file. This change also adds the ability to specify the JDK for the build to use. Change-Id: I0e2b43d889593e01d6ad0761960c93472990af1e Reviewed-on: https://review.openstack.org/16983 Reviewed-by: Clark Boylan Reviewed-by: James E. Blair Approved: Jeremy Stanley Reviewed-by: Jeremy Stanley Tested-by: Jenkins --- doc/source/general.rst | 57 +++++++++++++++- jenkins_jobs/builder.py | 27 -------- jenkins_jobs/modules/assignednode.py | 42 ------------ jenkins_jobs/modules/general.py | 97 ++++++++++++++++++++++++++++ jenkins_jobs/modules/logrotate.py | 51 --------------- setup.py | 3 +- tools/run-compare-xml.sh | 6 +- 7 files changed, 155 insertions(+), 128 deletions(-) delete mode 100644 jenkins_jobs/modules/assignednode.py create mode 100644 jenkins_jobs/modules/general.py delete mode 100644 jenkins_jobs/modules/logrotate.py diff --git a/doc/source/general.rst b/doc/source/general.rst index 62c0452b1..9e6d7d802 100644 --- a/doc/source/general.rst +++ b/doc/source/general.rst @@ -3,8 +3,59 @@ General Job Configuration ========================= -.. automodule:: assignednode - :members: +The most straightforward way to create a job is simply to define a +Job in YAML. It looks like this:: -.. automodule:: logrotate + - job: + name: job-name + +That's not very useful, so you'll want to add some actions such as +:ref:`builders`, and perhaps :ref:`publishers`. Those are described +later. There are a few basic optional fields for a Job definition:: + + - job: + name: job-name + project-type: freestyle + defaults: global + disabled: false + concurrent: true + quiet-period: 5 + block-downstream: false + block-upstream: false + +:Job Parameters: + * **project-type**: + Defaults to "freestyle", but "maven" can also be specified. + + * **defaults**: + Specifies a set of `Defaults`_ to use for this job, defaults to + ''global''. If you have values that are common to all of your jobs, + create a ``global`` `Defaults`_ object to hold them, and no further + configuration of individual jobs is necessary. If some jobs + should not use the ``global`` defaults, use this field to specify a + different set of defaults. + + * **disabled**: + Boolean value to set whether or not this job should be disabled in + Jenkins. Defaults to ``false`` (job will be enabled). + + * **concurrent**: + Boolean value to set whether or not Jenkins can run this job + concurrently. Defaults to ``false``. + + * **quiet-period**: + Number of seconds to wait between consecutive runs of this job. + Defaults to ``0``. + + * **block-downstream**: + Boolean value to set whether or not this job must block while + downstream jobs are running. Downstream jobs are determined + transitively. Defaults to ``false``. + + * **block-upstream**: + Boolean value to set whether or not this job must block while + upstream jobs are running. Upstream jobs are determined + transitively. Defaults to ``false``. + +.. automodule:: general :members: diff --git a/jenkins_jobs/builder.py b/jenkins_jobs/builder.py index e29af2853..068e69c2a 100644 --- a/jenkins_jobs/builder.py +++ b/jenkins_jobs/builder.py @@ -171,33 +171,6 @@ class YamlParser(object): break def gen_xml(self, xml, data): - XML.SubElement(xml, 'actions') - description = XML.SubElement(xml, 'description') - description.text = data.get('description', '') - XML.SubElement(xml, 'keepDependencies').text = 'false' - if data.get('disabled'): - XML.SubElement(xml, 'disabled').text = 'true' - else: - XML.SubElement(xml, 'disabled').text = 'false' - if data.get('block-downstream'): - XML.SubElement(xml, - 'blockBuildWhenDownstreamBuilding').text = 'true' - else: - XML.SubElement(xml, - 'blockBuildWhenDownstreamBuilding').text = 'false' - if data.get('block-upstream'): - XML.SubElement(xml, - 'blockBuildWhenUpstreamBuilding').text = 'true' - else: - XML.SubElement(xml, - 'blockBuildWhenUpstreamBuilding').text = 'false' - if data.get('concurrent'): - XML.SubElement(xml, 'concurrentBuild').text = 'true' - else: - XML.SubElement(xml, 'concurrentBuild').text = 'false' - if('quiet-period' in data): - XML.SubElement(xml, 'quietPeriod').text = str(data['quiet-period']) - for module in self.registry.modules: if hasattr(module, 'gen_xml'): module.gen_xml(self, xml, data) diff --git a/jenkins_jobs/modules/assignednode.py b/jenkins_jobs/modules/assignednode.py deleted file mode 100644 index 4c7603574..000000000 --- a/jenkins_jobs/modules/assignednode.py +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright 2012 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 Assigned Node section allows you to specify which Jenkins node (or -named group) should run the specified job. It adds the ``node`` -attribute to the :ref:`Job` definition. - -Example:: - - job: - name: test_job - node: precise - -That speficies that the job should be run on a Jenkins node or node group -named ``precise``. -""" - -import xml.etree.ElementTree as XML -import jenkins_jobs.modules.base - - -class AssignedNode(jenkins_jobs.modules.base.Base): - sequence = 40 - - def gen_xml(self, parser, xml_parent, data): - node = data.get('node', None) - if node: - XML.SubElement(xml_parent, 'assignedNode').text = node - XML.SubElement(xml_parent, 'canRoam').text = 'false' diff --git a/jenkins_jobs/modules/general.py b/jenkins_jobs/modules/general.py new file mode 100644 index 000000000..b440019fb --- /dev/null +++ b/jenkins_jobs/modules/general.py @@ -0,0 +1,97 @@ +# Copyright 2012 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 Logrotate section allows you to automatically remove old build +history. It adds the ``logrotate`` attribute to the :ref:`Job` +definition. + +Example:: + + - job: + name: test_job + logrotate: + daysToKeep: 3 + numToKeep: 20 + artifactDaysToKeep: -1 + artifactNumToKeep: -1 + +The Assigned Node section allows you to specify which Jenkins node (or +named group) should run the specified job. It adds the ``node`` +attribute to the :ref:`Job` definition. + +Example:: + + - job: + name: test_job + node: precise + +That speficies that the job should be run on a Jenkins node or node group +named ``precise``. +""" + + +import xml.etree.ElementTree as XML +import jenkins_jobs.modules.base + + +class General(jenkins_jobs.modules.base.Base): + sequence = 10 + + def gen_xml(self, parser, xml, data): + jdk = data.get('jdk', None) + if jdk: + XML.SubElement(xml, 'jdk').text = jdk + XML.SubElement(xml, 'actions') + description = XML.SubElement(xml, 'description') + description.text = data.get('description', '') + XML.SubElement(xml, 'keepDependencies').text = 'false' + if data.get('disabled'): + XML.SubElement(xml, 'disabled').text = 'true' + else: + XML.SubElement(xml, 'disabled').text = 'false' + if data.get('block-downstream'): + XML.SubElement(xml, + 'blockBuildWhenDownstreamBuilding').text = 'true' + else: + XML.SubElement(xml, + 'blockBuildWhenDownstreamBuilding').text = 'false' + if data.get('block-upstream'): + XML.SubElement(xml, + 'blockBuildWhenUpstreamBuilding').text = 'true' + else: + XML.SubElement(xml, + 'blockBuildWhenUpstreamBuilding').text = 'false' + if data.get('concurrent'): + XML.SubElement(xml, 'concurrentBuild').text = 'true' + else: + XML.SubElement(xml, 'concurrentBuild').text = 'false' + if('quiet-period' in data): + XML.SubElement(xml, 'quietPeriod').text = str(data['quiet-period']) + node = data.get('node', None) + if node: + XML.SubElement(xml, 'assignedNode').text = node + XML.SubElement(xml, 'canRoam').text = 'false' + if 'logrotate' in data: + lr_xml = XML.SubElement(xml, 'logRotator') + logrotate = data['logrotate'] + lr_days = XML.SubElement(lr_xml, 'daysToKeep') + lr_days.text = str(logrotate['daysToKeep']) + lr_num = XML.SubElement(lr_xml, 'numToKeep') + lr_num.text = str(logrotate['numToKeep']) + lr_adays = XML.SubElement(lr_xml, 'artifactDaysToKeep') + lr_adays.text = str(logrotate['artifactDaysToKeep']) + lr_anum = XML.SubElement(lr_xml, 'artifactNumToKeep') + lr_anum.text = str(logrotate['artifactNumToKeep']) diff --git a/jenkins_jobs/modules/logrotate.py b/jenkins_jobs/modules/logrotate.py deleted file mode 100644 index 6d5b8bcb0..000000000 --- a/jenkins_jobs/modules/logrotate.py +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright 2012 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 Logrotate section allows you to automatically remove old build -history. It adds the ``logrotate`` attribute to the :ref:`Job` -definition. - -Example:: - - job: - name: test_job - logrotate: - daysToKeep: 3 - numToKeep: 20 - artifactDaysToKeep: -1 - artifactNumToKeep: -1 -""" - - -import xml.etree.ElementTree as XML -import jenkins_jobs.modules.base - - -class LogRotate(jenkins_jobs.modules.base.Base): - sequence = 10 - - def gen_xml(self, parser, xml_parent, data): - if 'logrotate' in data: - lr_xml = XML.SubElement(xml_parent, 'logRotator') - logrotate = data['logrotate'] - lr_days = XML.SubElement(lr_xml, 'daysToKeep') - lr_days.text = str(logrotate['daysToKeep']) - lr_num = XML.SubElement(lr_xml, 'numToKeep') - lr_num.text = str(logrotate['numToKeep']) - lr_adays = XML.SubElement(lr_xml, 'artifactDaysToKeep') - lr_adays.text = str(logrotate['artifactDaysToKeep']) - lr_anum = XML.SubElement(lr_xml, 'artifactNumToKeep') - lr_anum.text = str(logrotate['artifactNumToKeep']) diff --git a/setup.py b/setup.py index 62efcbb93..a27800826 100644 --- a/setup.py +++ b/setup.py @@ -135,9 +135,8 @@ setuptools.setup( 'inject=jenkins_jobs.modules.wrappers:inject', ], 'jenkins_jobs.modules': [ - 'assignednode=jenkins_jobs.modules.assignednode:AssignedNode', + 'general=jenkins_jobs.modules.general:General', 'builders=jenkins_jobs.modules.builders:Builders', - 'logrotate=jenkins_jobs.modules.logrotate:LogRotate', 'properties=jenkins_jobs.modules.properties:Properties', 'parameters=jenkins_jobs.modules.parameters:Parameters', 'notifications=jenkins_jobs.modules.notifications:Notifications', diff --git a/tools/run-compare-xml.sh b/tools/run-compare-xml.sh index d1eee667d..7124b185b 100755 --- a/tools/run-compare-xml.sh +++ b/tools/run-compare-xml.sh @@ -22,9 +22,9 @@ mkdir -p .test/old/out mkdir -p .test/new/config mkdir -p .test/new/out cd .test -git clone https://review.openstack.org/p/openstack/openstack-ci-puppet --depth 1 -cp openstack-ci-puppet/modules/openstack_project/files/jenkins_job_builder/config/* old/config -cp openstack-ci-puppet/modules/openstack_project/files/jenkins_job_builder/config/* new/config +git clone https://review.openstack.org/p/openstack-infra/config --depth 1 +cp config/modules/openstack_project/files/jenkins_job_builder/config/* old/config +cp config/modules/openstack_project/files/jenkins_job_builder/config/* new/config cd .. GITHEAD=`git rev-parse HEAD`