
Switch to using entry points for loading modules as well as individual buliders, triggers, publishers, etc. Remove most openstack-specific python code. Change templating so it's less repetitive -- a single project definition will suffice for multiple jobs or job-groups. This outputs XML that is identical to the current production XML, warts and all. There are significant improvements that can be made to the YAML in a separate change, as they will cause minor changes to existing jobs (adding timestamps, logrotate, etc.). These are mostly marked with TODO in this change. Change-Id: Idcfddb3b43b6cfef4b20919a84540706d7a0a0b1 Reviewed-on: https://review.openstack.org/11000 Approved: James E. Blair <corvus@inaugust.com> Reviewed-by: James E. Blair <corvus@inaugust.com> Tested-by: Jenkins
118 lines
4.6 KiB
Python
118 lines
4.6 KiB
Python
# 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.
|
|
|
|
# Jenkins Job module for job properties
|
|
# No additional YAML needed
|
|
|
|
import xml.etree.ElementTree as XML
|
|
import jenkins_jobs.modules.base
|
|
|
|
def github(parser, xml_parent, data):
|
|
github = XML.SubElement(xml_parent,
|
|
'com.coravy.hudson.plugins.github.GithubProjectProperty')
|
|
github_url = XML.SubElement(github, 'projectUrl')
|
|
github_url.text = data['url']
|
|
|
|
def throttle(parser, xml_parent, data):
|
|
throttle = XML.SubElement(xml_parent,
|
|
'hudson.plugins.throttleconcurrents.ThrottleJobProperty')
|
|
XML.SubElement(throttle, 'maxConcurrentPerNode').text = str(
|
|
data.get('max-per-node'))
|
|
XML.SubElement(throttle, 'maxConcurrentTotal').text = str(
|
|
data.get('max-total'))
|
|
# TODO: What's "categories"?
|
|
#XML.SubElement(throttle, 'categories')
|
|
if data.get('enabled', True):
|
|
XML.SubElement(throttle, 'throttleEnabled').text = 'true'
|
|
else:
|
|
XML.SubElement(throttle, 'throttleEnabled').text = 'false'
|
|
XML.SubElement(throttle, 'throttleOption').text = data.get('option')
|
|
XML.SubElement(throttle, 'configVersion').text = '1'
|
|
|
|
def authenticated_build(parser, xml_parent, data):
|
|
# TODO: generalize this
|
|
if data:
|
|
security = XML.SubElement(xml_parent,
|
|
'hudson.security.AuthorizationMatrixProperty')
|
|
XML.SubElement(security, 'permission').text = \
|
|
'hudson.model.Item.Build:authenticated'
|
|
|
|
def base_param(parser, xml_parent, data, do_default, ptype):
|
|
pdef = XML.SubElement(xml_parent, ptype)
|
|
XML.SubElement(pdef, 'name').text = data['name']
|
|
XML.SubElement(pdef, 'description').text = data['description']
|
|
if do_default:
|
|
default = data.get('default', None)
|
|
if default:
|
|
XML.SubElement(pdef, 'defaultValue').text = default
|
|
else:
|
|
XML.SubElement(pdef, 'defaultValue')
|
|
|
|
def string_param(parser, xml_parent, data):
|
|
base_param(parser, xml_parent, data, True,
|
|
'hudson.model.StringParameterDefinition')
|
|
|
|
def bool_param(parser, xml_parent, data):
|
|
base_param(parser, xml_parent, data, True,
|
|
'hudson.model.BooleanParameterDefinition')
|
|
|
|
def file_param(parser, xml_parent, data):
|
|
base_param(parser, xml_parent, data, False,
|
|
'hudson.model.FileParameterDefinition')
|
|
|
|
def text_param(parser, xml_parent, data):
|
|
base_param(parser, xml_parent, data, True,
|
|
'hudson.model.TextParameterDefinition')
|
|
|
|
def label_param(parser, xml_parent, data):
|
|
base_param(parser, xml_parent, data, True,
|
|
'org.jvnet.jenkins.plugins.nodelabelparameter.LabelParameterDefinition')
|
|
|
|
def http_endpoint(parser, xml_parent, data):
|
|
endpoint_element = XML.SubElement(xml_parent,
|
|
'com.tikal.hudson.plugins.notification.Endpoint')
|
|
XML.SubElement(endpoint_element, 'protocol').text = 'HTTP'
|
|
XML.SubElement(endpoint_element, 'url').text = data['url']
|
|
|
|
|
|
class Properties(jenkins_jobs.modules.base.Base):
|
|
sequence = 20
|
|
|
|
def gen_xml(self, parser, xml_parent, data):
|
|
properties = XML.SubElement(xml_parent, 'properties')
|
|
|
|
for prop in data.get('properties', []):
|
|
self._dispatch('property', 'properties',
|
|
parser, properties, prop)
|
|
|
|
parameters = data.get('parameters', [])
|
|
if parameters:
|
|
pdefp = XML.SubElement(properties,
|
|
'hudson.model.ParametersDefinitionProperty')
|
|
pdefs = XML.SubElement(pdefp, 'parameterDefinitions')
|
|
for param in parameters:
|
|
self._dispatch('parameter', 'parameters',
|
|
parser, pdefs, param)
|
|
|
|
notifications = data.get('notifications', [])
|
|
if notifications:
|
|
notify_element = XML.SubElement(properties,
|
|
'com.tikal.hudson.plugins.notification.HudsonNotificationProperty')
|
|
endpoints_element = XML.SubElement(notify_element, 'endpoints')
|
|
|
|
for endpoint in notifications:
|
|
self._dispatch('notification', 'notifications',
|
|
parser, endpoints_element, endpoint)
|
|
|