summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortanhengyeow <E0032242@u.nus.edu>2018-07-21 17:07:23 +0800
committertanhengyeow <E0032242@u.nus.edu>2018-07-26 01:49:33 +0800
commitee86bc318c53013a1fc9dafabc1cdeb9f97ff216 (patch)
treefb756971ddc6fcecf11f10cd304717d0b37a714e
parent3b777009f3056ffd52b618ac08d1e0b485cd33f6 (diff)
Add support for "Invoke Nexus Policy Evaluation"
Change-Id: I363e468cdb4b50a0c6cf924d00618fb0ec568588 Signed-off-by: Tan Heng Yeow <E0032242@u.nus.edu>
Notes
Notes (review): Code-Review+2: Thanh Ha <zxiiro@gmail.com> Code-Review+2: Kien Ha <kienha9922@gmail.com> Workflow+1: Kien Ha <kienha9922@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Wed, 25 Jul 2018 19:38:35 +0000 Reviewed-on: https://review.openstack.org/584581 Project: openstack-infra/jenkins-job-builder Branch: refs/heads/master
-rw-r--r--jenkins_jobs/modules/builders.py89
-rw-r--r--tests/builders/fixtures/nexus-iq-policy-evaluator-full.xml20
-rw-r--r--tests/builders/fixtures/nexus-iq-policy-evaluator-full.yaml9
-rw-r--r--tests/builders/fixtures/nexus-iq-policy-evaluator-minimal.xml13
-rw-r--r--tests/builders/fixtures/nexus-iq-policy-evaluator-minimal.yaml4
5 files changed, 135 insertions, 0 deletions
diff --git a/jenkins_jobs/modules/builders.py b/jenkins_jobs/modules/builders.py
index 959345d..77ca9e4 100644
--- a/jenkins_jobs/modules/builders.py
+++ b/jenkins_jobs/modules/builders.py
@@ -4083,6 +4083,95 @@ def nexus_artifact_uploader(registry, xml_parent, data):
4083 nexus_artifact_uploader, data, mapping, fail_required=True) 4083 nexus_artifact_uploader, data, mapping, fail_required=True)
4084 4084
4085 4085
4086def nexus_iq_policy_evaluator(registry, xml_parent, data):
4087 """yaml: nexus-iq-policy-evaluator
4088 Integrates the Nexus Lifecycle into a Jenkins job.
4089 This function triggers 'Invokes Nexus Policy Evaluation'.
4090 Requires the Jenkins :jenkins-wiki:`Nexus
4091 Platform Plugin <Nexus+Platform+Plugin>`.
4092
4093 :arg str stage: Controls the stage the policy evaluation will be
4094 run against on the Nexus IQ Server (required)
4095
4096 :stage values:
4097 * **build**
4098 * **stage-release**
4099 * **operate**
4100 :arg dict application-type: Specifies an IQ Application (default manual)
4101
4102 :application-type values:
4103 * **manual**
4104 * **selected**
4105 :arg str application-id: Specify the IQ Application ID (required)
4106 :arg list scan-patterns: List of Ant-style patterns relative to the
4107 workspace root that denote files/archives to be scanned (default [])
4108 :arg bool fail-build-network-error: Controls the build outcome if there
4109 is a failure in communicating with the Nexus IQ Server (default false)
4110
4111 Minimal Example:
4112
4113 .. literalinclude::
4114 /../../tests/builders/fixtures/nexus-iq-policy-evaluator-minimal.yaml
4115 :language: yaml
4116
4117 Full Example:
4118
4119 .. literalinclude::
4120 /../../tests/builders/fixtures/nexus-iq-policy-evaluator-full.yaml
4121 :language: yaml
4122 """
4123 nexus_iq_policy_evaluator = XML.SubElement(
4124 xml_parent,
4125 'org.sonatype.nexus.ci.iq.IqPolicyEvaluatorBuildStep')
4126
4127 format_dict = {
4128 'stage': 'com__sonatype__nexus__ci__iq__IqPolicyEvaluator____iqStage',
4129 'fone': 'com__sonatype__nexus__ci__iq__IqPolicyEvaluator'
4130 '____failBuildOnNetworkError',
4131 }
4132
4133 valid_stages = ['build', 'stage-release', 'operate']
4134 mapping = [
4135 ('stage', format_dict.get('stage'), None, valid_stages),
4136 ('fail-build-network-error', format_dict.get('fone'), False),
4137 ]
4138 helpers.convert_mapping_to_xml(
4139 nexus_iq_policy_evaluator, data, mapping, fail_required=True)
4140
4141 application_type_label = data.get('application-type', 'manual').lower()
4142 application_type_label_dict = {
4143 'manual': 'org.sonatype.nexus.ci.iq.ManualApplication',
4144 'selected': 'org.sonatype.nexus.ci.iq.SelectedApplication',
4145 }
4146 if application_type_label not in application_type_label_dict:
4147 raise InvalidAttributeError(application_type_label,
4148 application_type_label,
4149 application_type_label_dict.keys())
4150
4151 application_type_tag = XML.SubElement(
4152 nexus_iq_policy_evaluator,
4153 'com__sonatype__nexus__ci__iq__IqPolicyEvaluator____iqApplication')
4154 application_type_tag.set(
4155 "class", application_type_label_dict[application_type_label]
4156 )
4157
4158 mapping = [
4159 ('application-id', 'applicationId', None),
4160 ]
4161 helpers.convert_mapping_to_xml(application_type_tag, data,
4162 mapping, fail_required=True)
4163
4164 scan_pattern_list = data.get('scan-patterns', [])
4165 iq_scan_pattern_tag = XML.SubElement(nexus_iq_policy_evaluator,
4166 'com__sonatype__nexus__ci__iq'
4167 '__IqPolicyEvaluator____iqScanPatterns')
4168
4169 for scan_pattern in scan_pattern_list:
4170 scan_pattern_tag = XML.SubElement(
4171 iq_scan_pattern_tag, 'org.sonatype.nexus.ci.iq.ScanPattern')
4172 XML.SubElement(scan_pattern_tag, 'scanPattern').text = scan_pattern
4173
4174
4086def ansible_playbook(parser, xml_parent, data): 4175def ansible_playbook(parser, xml_parent, data):
4087 """yaml: ansible-playbook 4176 """yaml: ansible-playbook
4088 This plugin allows you to execute Ansible tasks as a job build step. 4177 This plugin allows you to execute Ansible tasks as a job build step.
diff --git a/tests/builders/fixtures/nexus-iq-policy-evaluator-full.xml b/tests/builders/fixtures/nexus-iq-policy-evaluator-full.xml
new file mode 100644
index 0000000..eb5928c
--- /dev/null
+++ b/tests/builders/fixtures/nexus-iq-policy-evaluator-full.xml
@@ -0,0 +1,20 @@
1<?xml version="1.0" encoding="utf-8"?>
2<project>
3 <builders>
4 <org.sonatype.nexus.ci.iq.IqPolicyEvaluatorBuildStep>
5 <com__sonatype__nexus__ci__iq__IqPolicyEvaluator____iqStage>stage-release</com__sonatype__nexus__ci__iq__IqPolicyEvaluator____iqStage>
6 <com__sonatype__nexus__ci__iq__IqPolicyEvaluator____failBuildOnNetworkError>true</com__sonatype__nexus__ci__iq__IqPolicyEvaluator____failBuildOnNetworkError>
7 <com__sonatype__nexus__ci__iq__IqPolicyEvaluator____iqApplication class="org.sonatype.nexus.ci.iq.SelectedApplication">
8 <applicationId>nexus-iq-application-id002</applicationId>
9 </com__sonatype__nexus__ci__iq__IqPolicyEvaluator____iqApplication>
10 <com__sonatype__nexus__ci__iq__IqPolicyEvaluator____iqScanPatterns>
11 <org.sonatype.nexus.ci.iq.ScanPattern>
12 <scanPattern>**/target/*.war</scanPattern>
13 </org.sonatype.nexus.ci.iq.ScanPattern>
14 <org.sonatype.nexus.ci.iq.ScanPattern>
15 <scanPattern>**/target/*.ear</scanPattern>
16 </org.sonatype.nexus.ci.iq.ScanPattern>
17 </com__sonatype__nexus__ci__iq__IqPolicyEvaluator____iqScanPatterns>
18 </org.sonatype.nexus.ci.iq.IqPolicyEvaluatorBuildStep>
19 </builders>
20</project>
diff --git a/tests/builders/fixtures/nexus-iq-policy-evaluator-full.yaml b/tests/builders/fixtures/nexus-iq-policy-evaluator-full.yaml
new file mode 100644
index 0000000..c5b79bf
--- /dev/null
+++ b/tests/builders/fixtures/nexus-iq-policy-evaluator-full.yaml
@@ -0,0 +1,9 @@
1builders:
2 - nexus-iq-policy-evaluator:
3 stage: 'stage-release'
4 application-type: 'selected'
5 application-id: 'nexus-iq-application-id002'
6 scan-patterns:
7 - '**/target/*.war'
8 - '**/target/*.ear'
9 fail-build-network-error: true
diff --git a/tests/builders/fixtures/nexus-iq-policy-evaluator-minimal.xml b/tests/builders/fixtures/nexus-iq-policy-evaluator-minimal.xml
new file mode 100644
index 0000000..5515b1f
--- /dev/null
+++ b/tests/builders/fixtures/nexus-iq-policy-evaluator-minimal.xml
@@ -0,0 +1,13 @@
1<?xml version="1.0" encoding="utf-8"?>
2<project>
3 <builders>
4 <org.sonatype.nexus.ci.iq.IqPolicyEvaluatorBuildStep>
5 <com__sonatype__nexus__ci__iq__IqPolicyEvaluator____iqStage>build</com__sonatype__nexus__ci__iq__IqPolicyEvaluator____iqStage>
6 <com__sonatype__nexus__ci__iq__IqPolicyEvaluator____failBuildOnNetworkError>false</com__sonatype__nexus__ci__iq__IqPolicyEvaluator____failBuildOnNetworkError>
7 <com__sonatype__nexus__ci__iq__IqPolicyEvaluator____iqApplication class="org.sonatype.nexus.ci.iq.ManualApplication">
8 <applicationId>nexus-iq-application-id001</applicationId>
9 </com__sonatype__nexus__ci__iq__IqPolicyEvaluator____iqApplication>
10 <com__sonatype__nexus__ci__iq__IqPolicyEvaluator____iqScanPatterns/>
11 </org.sonatype.nexus.ci.iq.IqPolicyEvaluatorBuildStep>
12 </builders>
13</project>
diff --git a/tests/builders/fixtures/nexus-iq-policy-evaluator-minimal.yaml b/tests/builders/fixtures/nexus-iq-policy-evaluator-minimal.yaml
new file mode 100644
index 0000000..b8bd009
--- /dev/null
+++ b/tests/builders/fixtures/nexus-iq-policy-evaluator-minimal.yaml
@@ -0,0 +1,4 @@
1builders:
2 - nexus-iq-policy-evaluator:
3 stage: 'build'
4 application-id: 'nexus-iq-application-id001'