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 <kienha9922@gmail.com>
This commit is contained in:
Kien Ha 2016-06-06 14:40:05 -04:00
parent 7d13236760
commit 704f28c748
5 changed files with 90 additions and 34 deletions

View File

@ -2577,53 +2577,78 @@ def sonatype_clm(parser, xml_parent, data):
Requires the Jenkins :jenkins-wiki:`Sonatype CLM Plugin Requires the Jenkins :jenkins-wiki:`Sonatype CLM Plugin
<Sonatype+CLM+%28formerly+Insight+for+CI%29>`. <Sonatype+CLM+%28formerly+Insight+for+CI%29>`.
: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 :arg str application-name: Determines the policy elements to associate
with this build. (required) 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 :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 :arg str stage: Controls the stage the policy evaluation will be run
against on the CLM server. Valid stages: build, stage-release, release, against on the CLM server. Valid stages: build, stage-release, release,
operate. (default 'build') operate. (default: 'build')
:arg str scan-targets: Pattern of files to include for scanning. (optional) :arg str scan-targets: Pattern of files to include for scanning.
:arg str module-excludes: Pattern of files to exclude. (optional) (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 :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 :language: yaml
""" """
clm = XML.SubElement(xml_parent, clm = XML.SubElement(xml_parent,
'com.sonatype.insight.ci.hudson.PreBuildScan') 'com.sonatype.insight.ci.hudson.PreBuildScan')
clm.set('plugin', 'sonatype-clm-ci') clm.set('plugin', 'sonatype-clm-ci')
if 'application-name' not in data: SUPPORTED_VALUES = ['list', 'manual']
raise MissingAttributeError("application-name", clm_value = data.get('value')
"builders.sonatype-clm") if clm_value and clm_value not in SUPPORTED_VALUES:
XML.SubElement(clm, 'billOfMaterialsToken').text = str( raise InvalidAttributeError('value',
data['application-name']) clm_value,
XML.SubElement(clm, 'failOnClmServerFailures').text = str( SUPPORTED_VALUES)
data.get('fail-on-clm-server-failure', False)).lower()
SUPPORTED_STAGES = ['build', 'stage-release', 'release', 'operate'] SUPPORTED_STAGES = ['build', 'stage-release', 'release', 'operate']
stage = str(data.get('stage', 'build')).lower() clm_stage = data.get('stage')
if stage not in SUPPORTED_STAGES: if clm_stage and clm_stage not in SUPPORTED_STAGES:
raise InvalidAttributeError("stage", raise InvalidAttributeError('stage',
stage, clm_stage,
"builders.sonatype-clm",
SUPPORTED_STAGES) SUPPORTED_STAGES)
XML.SubElement(clm, 'stageId').text = stage
# Path Configs application_select = XML.SubElement(clm,
path_config = XML.SubElement(clm, 'applicationSelectType')
'pathConfig') application_mappings = [
XML.SubElement(path_config, 'scanTargets').text = str( ('value', 'value', 'list'),
data.get('scan-targets', '')).lower() ('application-name', 'applicationId', None),
XML.SubElement(path_config, 'moduleExcludes').text = str( ]
data.get('module-excludes', '')).lower() convert_mapping_to_xml(
XML.SubElement(path_config, 'scanProperties').text = str( application_select, data, application_mappings, fail_required=True)
data.get('advanced-options', '')).lower()
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): def beaker(parser, xml_parent, data):

View File

@ -2,14 +2,19 @@
<project> <project>
<builders> <builders>
<com.sonatype.insight.ci.hudson.PreBuildScan plugin="sonatype-clm-ci"> <com.sonatype.insight.ci.hudson.PreBuildScan plugin="sonatype-clm-ci">
<billOfMaterialsToken>jenkins-job-builder</billOfMaterialsToken> <applicationSelectType>
<failOnClmServerFailures>true</failOnClmServerFailures> <value>manual</value>
<stageId>release</stageId> <applicationId>jenkins-job-builder</applicationId>
</applicationSelectType>
<pathConfig> <pathConfig>
<scanTargets>**/*.jar</scanTargets> <scanTargets>**/*.jar</scanTargets>
<moduleExcludes>**/my-module/target/**</moduleExcludes> <moduleExcludes>**/my-module/target/**</moduleExcludes>
<scanProperties>test</scanProperties> <scanProperties>test</scanProperties>
</pathConfig> </pathConfig>
<failOnClmServerFailures>true</failOnClmServerFailures>
<stageId>build</stageId>
<username>bar</username>
<password>06XQY39LHGACt3r3kzSULg==</password>
</com.sonatype.insight.ci.hudson.PreBuildScan> </com.sonatype.insight.ci.hudson.PreBuildScan>
</builders> </builders>
</project> </project>

View File

@ -1,8 +1,11 @@
builders: builders:
- sonatype-clm: - sonatype-clm:
value: manual
application-name: jenkins-job-builder application-name: jenkins-job-builder
fail-on-clm-server-failure: true fail-on-clm-server-failure: true
stage: release stage: build
scan-targets: '**/*.jar' scan-targets: '**/*.jar'
module-excludes: '**/my-module/target/**' module-excludes: '**/my-module/target/**'
advanced-options: 'test' advanced-options: 'test'
username: bar
password: 06XQY39LHGACt3r3kzSULg==

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<project>
<builders>
<com.sonatype.insight.ci.hudson.PreBuildScan plugin="sonatype-clm-ci">
<applicationSelectType>
<value>list</value>
<applicationId>jenkins-job-builder</applicationId>
</applicationSelectType>
<pathConfig>
<scanTargets/>
<moduleExcludes/>
<scanProperties/>
</pathConfig>
<failOnClmServerFailures>false</failOnClmServerFailures>
<stageId>build</stageId>
<username/>
<password/>
</com.sonatype.insight.ci.hudson.PreBuildScan>
</builders>
</project>

View File

@ -0,0 +1,3 @@
builders:
- sonatype-clm:
application-name: jenkins-job-builder