Debian Codegraph @

jenkins_jobs/modules/reporters.py

raw
1 # Copyright 2012 Hewlett-Packard Development Company, L.P.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
13 # under the License.
14
15
16 """
17 Reporters are like publishers but only applicable to Maven projects.
18
19 **Component**: reporters
20 :Macro: reporter
21 :Entry Point: jenkins_jobs.reporters
22
23 Example::
24
25 job:
26 name: test_job
27 project-type: maven
28
29 reporters:
30 - email:
31 recipients: [email protected]
32 """
33
34 import xml.etree.ElementTree as XML
35
36 from jenkins_jobs.errors import JenkinsJobsException
37 import jenkins_jobs.modules.base
38 import jenkins_jobs.modules.helpers as helpers
39
40
41 def email(registry, xml_parent, data):
42 """yaml: email
43 Email notifications on build failure.
44
45 :arg str recipients: Recipient email addresses
46 :arg bool notify-every-unstable-build: Send an email for every
47 unstable build (default true)
48 :arg bool send-to-individuals: Send an email to the individual
49 who broke the build (default false)
50 :arg bool notify-for-each-module: Send an email for each module
51 (e.g. failed, unstable). (default true)
52
53 Example::
54
55 reporters:
56 - email:
57 recipients: [email protected]
58 """
59
60 mailer = XML.SubElement(xml_parent, "hudson.maven.reporters.MavenMailer")
61 XML.SubElement(mailer, "recipients").text = data["recipients"]
62
63 # Note the logic reversal (included here to match the GUI
64 if data.get("notify-every-unstable-build", True):
65 XML.SubElement(mailer, "dontNotifyEveryUnstableBuild").text = "false"
66 else:
67 XML.SubElement(mailer, "dontNotifyEveryUnstableBuild").text = "true"
68 mapping = [
69 ("send-to-individuals", "sendToIndividuals", False),
70 ("notify-for-each-module", "perModuleEmail", True),
71 ]
72 helpers.convert_mapping_to_xml(mailer, data, mapping, fail_required=False)
73
74
75 def findbugs(registry, xml_parent, data):
76 """yaml: findbugs
77 FindBugs reporting for builds
78
79 Requires the Jenkins FindBugs Plugin
80 (:jenkins-github:`findbugs-plugin`).
81
82 :arg bool rank-priority: Use rank as priority (default false)
83 :arg str include-files: Comma separated list of files to include.
84 (Optional)
85 :arg str exclude-files: Comma separated list of files to exclude.
86 (Optional)
87 :arg bool can-run-on-failed: Weather or not to run plug-in on failed builds
88 (default false)
89 :arg int healthy: Sunny threshold (optional)
90 :arg int unhealthy: Stormy threshold (optional)
91 :arg str health-threshold: Threshold priority for health status
92 ('low', 'normal' or 'high', defaulted to 'low')
93 :arg bool dont-compute-new: If set to false, computes new warnings based on
94 the reference build (default true)
95 :arg bool use-delta-values: Use delta for new warnings. (default false)
96 :arg bool use-previous-build-as-reference: If set then the number of new
97 warnings will always be calculated based on the previous build.
98 Otherwise the reference build. (default false)
99 :arg bool use-stable-build-as-reference: The number of new warnings will be
100 calculated based on the last stable build, allowing reverts of unstable
101 builds where the number of warnings was decreased. (default false)
102 :arg dict thresholds:
103 :thresholds:
104 * **unstable** (`dict`)
105 :unstable: * **total-all** (`int`)
106 * **total-high** (`int`)
107 * **total-normal** (`int`)
108 * **total-low** (`int`)
109 * **new-all** (`int`)
110 * **new-high** (`int`)
111 * **new-normal** (`int`)
112 * **new-low** (`int`)
113
114 * **failed** (`dict`)
115 :failed: * **total-all** (`int`)
116 * **total-high** (`int`)
117 * **total-normal** (`int`)
118 * **total-low** (`int`)
119 * **new-all** (`int`)
120 * **new-high** (`int`)
121 * **new-normal** (`int`)
122 * **new-low** (`int`)
123
124 Minimal Example:
125
126 .. literalinclude:: /../../tests/reporters/fixtures/findbugs-minimal.yaml
127
128 Full Example:
129
130 .. literalinclude:: /../../tests/reporters/fixtures/findbugs01.yaml
131 """
132 findbugs = XML.SubElement(xml_parent, "hudson.plugins.findbugs.FindBugsReporter")
133 findbugs.set("plugin", "findbugs")
134
135 helpers.findbugs_settings(findbugs, data)
136 helpers.build_trends_publisher("[FINDBUGS] ", findbugs, data)
137
138
139 class Reporters(jenkins_jobs.modules.base.Base):
140 sequence = 55
141
142 component_type = "reporter"
143 component_list_type = "reporters"
144
145 def gen_xml(self, xml_parent, data):
146 if "reporters" not in data:
147 return
148
149 if xml_parent.tag != "maven2-moduleset":
150 raise JenkinsJobsException(
151 "Reporters may only be used for Maven " "modules."
152 )
153
154 xml_reporters = XML.SubElement(xml_parent, "reporters")
155
156 component_list = data.get("reporters", [])
157 self.dispatch_component_list("reporter", component_list, xml_reporters)