From 704f28c7482fe848291de9066a22df12aaca364b Mon Sep 17 00:00:00 2001 From: Kien Ha Date: Mon, 6 Jun 2016 14:40:05 -0400 Subject: [PATCH] Update Sonatype CLM for CI plugin - Update to use convert_mapping_to_xml - Add username, password, and value options - Update documentation Change-Id: I76de5f0a9f5169e09764e418733e9046b046ea09 Signed-off-by: Kien Ha --- jenkins_jobs/modules/builders.py | 85 ++++++++++++------- ...pe-clm01.xml => sonatype-clm-complete.xml} | 11 ++- ...-clm01.yaml => sonatype-clm-complete.yaml} | 5 +- .../fixtures/sonatype-clm-minimal.xml | 20 +++++ .../fixtures/sonatype-clm-minimal.yaml | 3 + 5 files changed, 90 insertions(+), 34 deletions(-) rename tests/builders/fixtures/{sonatype-clm01.xml => sonatype-clm-complete.xml} (63%) rename tests/builders/fixtures/{sonatype-clm01.yaml => sonatype-clm-complete.yaml} (68%) create mode 100644 tests/builders/fixtures/sonatype-clm-minimal.xml create mode 100644 tests/builders/fixtures/sonatype-clm-minimal.yaml diff --git a/jenkins_jobs/modules/builders.py b/jenkins_jobs/modules/builders.py index d6bcac737..6b07bc70d 100644 --- a/jenkins_jobs/modules/builders.py +++ b/jenkins_jobs/modules/builders.py @@ -2577,53 +2577,78 @@ def sonatype_clm(parser, xml_parent, data): Requires the Jenkins :jenkins-wiki:`Sonatype CLM Plugin `. + :arg str value: Select CLM application from a list of available CLM + applications or specify CLM Application ID (default: list) :arg str application-name: Determines the policy elements to associate with this build. (required) + :arg str username: Username on the Sonatype CLM server. Leave empty to + use the username configured at global level. (default: '') + :arg str password: Password on the Sonatype CLM server. Leave empty to + use the password configured at global level. (default: '') :arg bool fail-on-clm-server-failure: Controls the build outcome if there - is a failure in communicating with the CLM server. (default false) + is a failure in communicating with the CLM server. (default: False) :arg str stage: Controls the stage the policy evaluation will be run against on the CLM server. Valid stages: build, stage-release, release, - operate. (default 'build') - :arg str scan-targets: Pattern of files to include for scanning. (optional) - :arg str module-excludes: Pattern of files to exclude. (optional) + operate. (default: 'build') + :arg str scan-targets: Pattern of files to include for scanning. + (default: '') + :arg str module-excludes: Pattern of files to exclude. (default: '') :arg str advanced-options: Options to be set on a case-by-case basis as - advised by Sonatype Support. (optional) + advised by Sonatype Support. (default: '') - Example: + Minimal Example: - .. literalinclude:: /../../tests/builders/fixtures/sonatype-clm01.yaml + .. literalinclude:: + /../../tests/builders/fixtures/sonatype-clm-minimal.yaml + :language: yaml + + Full Example: + + .. literalinclude:: + /../../tests/builders/fixtures/sonatype-clm-complete.yaml :language: yaml """ clm = XML.SubElement(xml_parent, 'com.sonatype.insight.ci.hudson.PreBuildScan') clm.set('plugin', 'sonatype-clm-ci') - if 'application-name' not in data: - raise MissingAttributeError("application-name", - "builders.sonatype-clm") - XML.SubElement(clm, 'billOfMaterialsToken').text = str( - data['application-name']) - XML.SubElement(clm, 'failOnClmServerFailures').text = str( - data.get('fail-on-clm-server-failure', False)).lower() - + SUPPORTED_VALUES = ['list', 'manual'] + clm_value = data.get('value') + if clm_value and clm_value not in SUPPORTED_VALUES: + raise InvalidAttributeError('value', + clm_value, + SUPPORTED_VALUES) SUPPORTED_STAGES = ['build', 'stage-release', 'release', 'operate'] - stage = str(data.get('stage', 'build')).lower() - if stage not in SUPPORTED_STAGES: - raise InvalidAttributeError("stage", - stage, - "builders.sonatype-clm", + clm_stage = data.get('stage') + if clm_stage and clm_stage not in SUPPORTED_STAGES: + raise InvalidAttributeError('stage', + clm_stage, SUPPORTED_STAGES) - XML.SubElement(clm, 'stageId').text = stage - # Path Configs - path_config = XML.SubElement(clm, - 'pathConfig') - XML.SubElement(path_config, 'scanTargets').text = str( - data.get('scan-targets', '')).lower() - XML.SubElement(path_config, 'moduleExcludes').text = str( - data.get('module-excludes', '')).lower() - XML.SubElement(path_config, 'scanProperties').text = str( - data.get('advanced-options', '')).lower() + application_select = XML.SubElement(clm, + 'applicationSelectType') + application_mappings = [ + ('value', 'value', 'list'), + ('application-name', 'applicationId', None), + ] + convert_mapping_to_xml( + application_select, data, application_mappings, fail_required=True) + + path = XML.SubElement(clm, 'pathConfig') + path_mappings = [ + ('scan-targets', 'scanTargets', ''), + ('module-excludes', 'moduleExcludes', ''), + ('advanced-options', 'scanProperties', ''), + ] + convert_mapping_to_xml(path, data, path_mappings, fail_required=True) + + mappings = [ + ('fail-on-clm-server-failure', 'failOnClmServerFailures', False), + ('stage', 'stageId', 'build'), + ('username', 'username', ''), + ('password', 'password', ''), + ] + convert_mapping_to_xml(clm, data, mappings, fail_required=True) def beaker(parser, xml_parent, data): diff --git a/tests/builders/fixtures/sonatype-clm01.xml b/tests/builders/fixtures/sonatype-clm-complete.xml similarity index 63% rename from tests/builders/fixtures/sonatype-clm01.xml rename to tests/builders/fixtures/sonatype-clm-complete.xml index c994cb362..6ad0873b1 100644 --- a/tests/builders/fixtures/sonatype-clm01.xml +++ b/tests/builders/fixtures/sonatype-clm-complete.xml @@ -2,14 +2,19 @@ - jenkins-job-builder - true - release + + manual + jenkins-job-builder + **/*.jar **/my-module/target/** test + true + build + bar + 06XQY39LHGACt3r3kzSULg== diff --git a/tests/builders/fixtures/sonatype-clm01.yaml b/tests/builders/fixtures/sonatype-clm-complete.yaml similarity index 68% rename from tests/builders/fixtures/sonatype-clm01.yaml rename to tests/builders/fixtures/sonatype-clm-complete.yaml index 5c8ddf638..1fcd40f3f 100644 --- a/tests/builders/fixtures/sonatype-clm01.yaml +++ b/tests/builders/fixtures/sonatype-clm-complete.yaml @@ -1,8 +1,11 @@ builders: - sonatype-clm: + value: manual application-name: jenkins-job-builder fail-on-clm-server-failure: true - stage: release + stage: build scan-targets: '**/*.jar' module-excludes: '**/my-module/target/**' advanced-options: 'test' + username: bar + password: 06XQY39LHGACt3r3kzSULg== diff --git a/tests/builders/fixtures/sonatype-clm-minimal.xml b/tests/builders/fixtures/sonatype-clm-minimal.xml new file mode 100644 index 000000000..d138ec268 --- /dev/null +++ b/tests/builders/fixtures/sonatype-clm-minimal.xml @@ -0,0 +1,20 @@ + + + + + + list + jenkins-job-builder + + + + + + + false + build + + + + + diff --git a/tests/builders/fixtures/sonatype-clm-minimal.yaml b/tests/builders/fixtures/sonatype-clm-minimal.yaml new file mode 100644 index 000000000..697901528 --- /dev/null +++ b/tests/builders/fixtures/sonatype-clm-minimal.yaml @@ -0,0 +1,3 @@ +builders: + - sonatype-clm: + application-name: jenkins-job-builder