diff --git a/jenkins_jobs/modules/parameters.py b/jenkins_jobs/modules/parameters.py index 8a914d1b8..36f7db00a 100644 --- a/jenkins_jobs/modules/parameters.py +++ b/jenkins_jobs/modules/parameters.py @@ -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 + `. + + :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 diff --git a/tests/parameters/fixtures/maven-metadata-param001.xml b/tests/parameters/fixtures/maven-metadata-param001.xml new file mode 100644 index 000000000..b0ee9ad9c --- /dev/null +++ b/tests/parameters/fixtures/maven-metadata-param001.xml @@ -0,0 +1,23 @@ + + + + + + + maven metadata param + + http://nexus.example.com + com.example + example + jar + FIRST + [0-9]+ + ASC + 5 + username + password + + + + + diff --git a/tests/parameters/fixtures/maven-metadata-param001.yaml b/tests/parameters/fixtures/maven-metadata-param001.yaml new file mode 100644 index 000000000..e7aab47cc --- /dev/null +++ b/tests/parameters/fixtures/maven-metadata-param001.yaml @@ -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"