Adding support for maven-metadata-plugin

Added a method called maven_metadata_param to deal with maven metadata
(https://wiki.jenkins-ci.org/display/JENKINS/Maven+Metadata+Plugin)
plus addition of relevant tests

Change-Id: Id04b33653cc90f69dd1588286352b9d19e852ece
This commit is contained in:
Nicolas Glayre 2015-12-14 15:57:17 +01:00
parent b14813ba78
commit bb6d4755a2
3 changed files with 101 additions and 0 deletions

View File

@ -36,6 +36,7 @@ import xml.etree.ElementTree as XML
from jenkins_jobs.errors import JenkinsJobsException
from jenkins_jobs.errors import MissingAttributeError
from jenkins_jobs.errors import InvalidAttributeError
import jenkins_jobs.modules.base
from jenkins_jobs.modules.helpers import copyartifact_build_selector
@ -654,6 +655,70 @@ def copyartifact_build_selector_param(parser, xml_parent, data):
copyartifact_build_selector(t, data, 'defaultSelector')
def maven_metadata_param(parser, xml_parent, data):
"""yaml: maven-metadata
This parameter allows the resolution of maven artifact versions
by contacting the repository and reading the maven-metadata.xml.
Requires the Jenkins :jenkins-wiki:`Maven Metadata Plugin
<Maven+Metadata+Plugin>`.
:arg str name: Name of the parameter
:arg str description: Description of the parameter (optional)
:arg str repository-base-url: URL from where you retrieve your artifacts
(default '')
:arg str repository-username: Repository's username if authentication is
required. (default '')
:arg str repository-password: Repository's password if authentication is
required. (default '')
:arg str artifact-group-id: Unique project identifier (default '')
:arg str artifact-id: Name of the artifact without version (default '')
:arg str packaging: Artifact packaging option. Could be something such as
jar, zip, pom.... (default '')
:arg str versions-filter: Specify a regular expression which will be used
to filter the versions which are actually displayed when triggering a
new build. (default '')
:arg str default-value: For features such as SVN polling a default value
is required. If job will only be started manually, this field is not
necessary. (default '')
:arg str maximum-versions-to-display: The maximum number of versions to
display in the drop-down. Any non-number value as well as 0 or negative
values will default to all. (default 10)
:arg str sorting-order: ascending or descending
(default descending)
Example:
.. literalinclude::
/../../tests/parameters/fixtures/maven-metadata-param001.yaml
:language: yaml
"""
pdef = base_param(parser, xml_parent, data, False,
'eu.markov.jenkins.plugin.mvnmeta.'
'MavenMetadataParameterDefinition')
XML.SubElement(pdef, 'repoBaseUrl').text = data.get('repository-base-url',
'')
XML.SubElement(pdef, 'groupId').text = data.get('artifact-group-id', '')
XML.SubElement(pdef, 'artifactId').text = data.get('artifact-id', '')
XML.SubElement(pdef, 'packaging').text = data.get('packaging', '')
XML.SubElement(pdef, 'defaultValue').text = data.get('default-value', '')
XML.SubElement(pdef, 'versionFilter').text = data.get('versions-filter',
'')
sort_order = data.get('sorting-order', 'descending').lower()
sort_dict = {'descending': 'DESC',
'ascending': 'ASC'}
if sort_order not in sort_dict:
raise InvalidAttributeError(sort_order, sort_order, sort_dict.keys())
XML.SubElement(pdef, 'sortOrder').text = sort_dict[sort_order]
XML.SubElement(pdef, 'maxVersions').text = str(data.get(
'maximum-versions-to-display', 10))
XML.SubElement(pdef, 'username').text = data.get('repository-username', '')
XML.SubElement(pdef, 'password').text = data.get('repository-password', '')
class Parameters(jenkins_jobs.modules.base.Base):
sequence = 21

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<properties>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<eu.markov.jenkins.plugin.mvnmeta.MavenMetadataParameterDefinition>
<name>maven metadata param</name>
<description/>
<repoBaseUrl>http://nexus.example.com</repoBaseUrl>
<groupId>com.example</groupId>
<artifactId>example</artifactId>
<packaging>jar</packaging>
<defaultValue>FIRST</defaultValue>
<versionFilter>[0-9]+</versionFilter>
<sortOrder>ASC</sortOrder>
<maxVersions>5</maxVersions>
<username>username</username>
<password>password</password>
</eu.markov.jenkins.plugin.mvnmeta.MavenMetadataParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
</properties>
</project>

View File

@ -0,0 +1,13 @@
parameters:
- maven-metadata:
name: 'maven metadata param'
repository-base-url: 'http://nexus.example.com'
repository-username: 'username'
repository-password: 'password'
artifact-group-id: 'com.example'
artifact-id: 'example'
packaging: 'jar'
versions-filter: '[0-9]+'
default-value: 'FIRST'
maximum-versions-to-display: "5"
sorting-order: "Ascending"