Browse Source

Merge "Add support for "Invoke Nexus Policy Evaluation""

tags/2.2.0^0
Zuul 10 months ago
parent
commit
cb6641d7f8

+ 89
- 0
jenkins_jobs/modules/builders.py View File

@@ -4083,6 +4083,95 @@ def nexus_artifact_uploader(registry, xml_parent, data):
4083 4083
         nexus_artifact_uploader, data, mapping, fail_required=True)
4084 4084
 
4085 4085
 
4086
+def 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
+
4086 4175
 def ansible_playbook(parser, xml_parent, data):
4087 4176
     """yaml: ansible-playbook
4088 4177
     This plugin allows you to execute Ansible tasks as a job build step.

+ 20
- 0
tests/builders/fixtures/nexus-iq-policy-evaluator-full.xml View File

@@ -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>

+ 9
- 0
tests/builders/fixtures/nexus-iq-policy-evaluator-full.yaml View File

@@ -0,0 +1,9 @@
1
+builders:
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

+ 13
- 0
tests/builders/fixtures/nexus-iq-policy-evaluator-minimal.xml View File

@@ -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>

+ 4
- 0
tests/builders/fixtures/nexus-iq-policy-evaluator-minimal.yaml View File

@@ -0,0 +1,4 @@
1
+builders:
2
+  - nexus-iq-policy-evaluator:
3
+      stage: 'build'
4
+      application-id: 'nexus-iq-application-id001'

Loading…
Cancel
Save