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 <clark.boylan@gmail.com>
Reviewed-by: James E. Blair <corvus@inaugust.com>
Approved: Jeremy Stanley <fungi@yuggoth.org>
Reviewed-by: Jeremy Stanley <fungi@yuggoth.org>
Tested-by: Jenkins
This commit is contained in:
william.soula 2012-11-27 10:23:10 -06:00 committed by Jenkins
parent 899ab4a980
commit eb210845e4
7 changed files with 155 additions and 128 deletions

View File

@ -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:

View File

@ -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)

View File

@ -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'

View File

@ -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'])

View File

@ -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'])

View File

@ -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',

View File

@ -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`