| 1 |
# Copyright 2020 Openstack Foundation |
| 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, |
| 11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
# See the License for the specific language governing permissions and |
| 13 |
# limitations under the License. |
| 14 |
|
| 15 |
""" |
| 16 |
The view delivery pipeline module handles creation of Delivery Pipeline views. |
| 17 |
To create a delivery pipeline view specify ``delivery_pipeline`` in the |
| 18 |
``view-type`` attribute to the :ref:`view_delivery_pipeline` definition. |
| 19 |
Requires the Jenkins :jenkins-plugins:`Delivery Pipeline Plugin |
| 20 |
<delivery-pipeline-plugin>`. |
| 21 |
|
| 22 |
:View Parameters: |
| 23 |
* **name** (`str`): The name of the view. |
| 24 |
* **view-type** (`str`): The type of view. |
| 25 |
* **description** (`str`): A description of the view. (optional) |
| 26 |
* **filter-executors** (`bool`): Show only executors that can |
| 27 |
execute the included views. (default false) |
| 28 |
* **filter-queue** (`bool`): Show only included jobs in builder |
| 29 |
queue. (default false) |
| 30 |
* **components** (`list`): |
| 31 |
* **name** (`str`): Name of the pipeline, usually the name of the |
| 32 |
component or product. |
| 33 |
* **initial-job** (`str`): First job in the pipeline. |
| 34 |
* **final-job** (`str`): Final job to display in the pipeline view |
| 35 |
regardless of its downstream jobs. (default '') |
| 36 |
* **show-upstream** (`bool`): Whether to show upstream. (default false) |
| 37 |
* **regexps** (`list`): |
| 38 |
* **regexp** (`str`): Regular expression to find initial jobs. |
| 39 |
* **show-upstream** (`bool`): Whether to show upstream. (default false) |
| 40 |
* **aggregated-changes-grouping-pattern** (`str`): Group changelog by regex |
| 41 |
pattern. (default '') |
| 42 |
* **allow-abort** (`bool`): Allow cancelling a running job from the |
| 43 |
delivery pipeline view. (default false) |
| 44 |
* **allow-manual-triggers** (`bool`): Displays a button in the pipeline |
| 45 |
view if a task is manual (Build other projects (manual step)) from Build |
| 46 |
Pipeline Plugin. (default false) |
| 47 |
* **allow-pipeline-start** (`bool`): Allow starting a new pipeline run from |
| 48 |
the delivery pipeline view. (default false) |
| 49 |
* **allow-rebuild** (`bool`): Allow rerunning a task from the delivery |
| 50 |
pipeline view. (default false) |
| 51 |
* **link-relative** (`bool`): Use relative links for jobs in this pipeline |
| 52 |
view to allow for easier navigation. (default false) |
| 53 |
* **link-to-console-log** (`bool`): Changes behaviour of task link in |
| 54 |
delivery pipeline view to go directly to the console log. (default false) |
| 55 |
* **max-number-of-visible-pipelines** (`int`): Limits the number of |
| 56 |
pipelines shown in the view, regardless of how many pipelines are |
| 57 |
configured. A negative value will not enforce a limit. |
| 58 |
* **no-of-columns** (`int`): Number of columns used for showing pipelines. |
| 59 |
Possible values are 1 (default), 2 and 3. |
| 60 |
* **no-of-pipelines** (`int`): Number of pipelines instances shown for each |
| 61 |
pipeline. Possible values are numbers from 1 to 50 (default 3). |
| 62 |
* **paging-enabled** (`bool`): Enable pagination in normal view, to allow |
| 63 |
navigation to older pipeline runs which are not displayed on the first |
| 64 |
page. Not available in full screen view. (default false) |
| 65 |
* **show-absolute-date-time** (`bool`): Show dates and times as absolute |
| 66 |
values instead of as relative to the current time. (default false) |
| 67 |
* **show-aggregated-changes** (`bool`): Show an aggregated changelog |
| 68 |
between different stages. (default false) |
| 69 |
* **show-aggregated-pipeline** (`bool`): Show an aggregated view where each |
| 70 |
stage shows the latest version being executed. (default false) |
| 71 |
* **show-avatars** (`bool`): Show avatars pictures instead of names of the |
| 72 |
people involved in a pipeline instance. (default false) |
| 73 |
* **show-changes** (`bool`): Show SCM change log for the first job in the |
| 74 |
pipeline. (default false) |
| 75 |
* **show-description** (`bool`): Show a build description connected to a |
| 76 |
specific pipeline task. (default false) |
| 77 |
* **show-promotions** (`bool`): Show promotions from Promoted Builds |
| 78 |
Plugin. (default false) |
| 79 |
* **show-static-analysis-results** (`bool`): Show different analysis |
| 80 |
results from Analysis Collector Plugin. (default false) |
| 81 |
* **show-test-results** (`bool`): Show test results as pass/failed/skipped. |
| 82 |
(default false) |
| 83 |
* **show-total-build-time** (`bool`): Show total build time for a pipeline |
| 84 |
run. (default false) |
| 85 |
* **sorting** (`str`): How to sort the pipelines in the current view. Only |
| 86 |
applicable when multiple pipelines are configured in the same view. |
| 87 |
Possible values are 'none' (default), 'title' (sort by title), |
| 88 |
'failed_last_activity' (sort by failed pipelines, then by last activity), |
| 89 |
'last_activity' (sort by last activity). |
| 90 |
* **update-interval** (`int`): How often the pipeline view will be updated. |
| 91 |
To be specified in seconds. (default 2) |
| 92 |
|
| 93 |
Minimal Example: |
| 94 |
|
| 95 |
.. literalinclude:: |
| 96 |
/../../tests/views/fixtures/view_delivery_pipeline-minimal.yaml |
| 97 |
|
| 98 |
Full Example: |
| 99 |
|
| 100 |
.. literalinclude:: |
| 101 |
/../../tests/views/fixtures/view_delivery_pipeline-full.yaml |
| 102 |
""" |
| 103 |
|
| 104 |
import xml.etree.ElementTree as XML |
| 105 |
import jenkins_jobs.modules.base |
| 106 |
import jenkins_jobs.modules.helpers as helpers |
| 107 |
|
| 108 |
|
| 109 |
class DeliveryPipeline(jenkins_jobs.modules.base.Base): |
| 110 |
def root_xml(self, data): |
| 111 |
root = XML.Element( |
| 112 |
"se.diabol.jenkins.pipeline.DeliveryPipelineView", |
| 113 |
{"plugin": "delivery-pipeline-plugin"}, |
| 114 |
) |
| 115 |
|
| 116 |
# Optional |
| 117 |
mapping_optional = [ |
| 118 |
("description", "description", None), |
| 119 |
("filter-executors", "filterExecutors", False), |
| 120 |
("filter-queue", "filterQueue", False), |
| 121 |
] |
| 122 |
helpers.convert_mapping_to_xml( |
| 123 |
root, data, mapping_optional, fail_required=False |
| 124 |
) |
| 125 |
|
| 126 |
# Required - simple |
| 127 |
mapping = [ |
| 128 |
( |
| 129 |
"aggregated-changes-grouping-pattern", |
| 130 |
"aggregatedChangesGroupingPattern", |
| 131 |
"", |
| 132 |
), |
| 133 |
("allow-abort", "allowAbort", False), |
| 134 |
("allow-manual-triggers", "allowManualTriggers", False), |
| 135 |
("allow-pipeline-start", "allowPipelineStart", False), |
| 136 |
("allow-rebuild", "allowRebuild", False), |
| 137 |
("link-relative", "linkRelative", False), |
| 138 |
("link-to-console-log", "linkToConsoleLog", False), |
| 139 |
("max-number-of-visible-pipelines", "maxNumberOfVisiblePipelines", -1), |
| 140 |
("name", "name", None), |
| 141 |
("no-of-columns", "noOfColumns", 1, [1, 2, 3]), |
| 142 |
("no-of-pipelines", "noOfPipelines", 3, list(range(51))), |
| 143 |
("paging-enabled", "pagingEnabled", False), |
| 144 |
("show-absolute-date-time", "showAbsoluteDateTime", False), |
| 145 |
("show-aggregated-changes", "showAggregatedChanges", False), |
| 146 |
("show-aggregated-pipeline", "showAggregatedPipeline", False), |
| 147 |
("show-avatars", "showAvatars", False), |
| 148 |
("show-changes", "showChanges", False), |
| 149 |
("show-description", "showDescription", False), |
| 150 |
("show-promotions", "showPromotions", False), |
| 151 |
("show-static-analysis-results", "showStaticAnalysisResults", False), |
| 152 |
("show-test-results", "showTestResults", False), |
| 153 |
("show-total-build-time", "showTotalBuildTime", False), |
| 154 |
("update-interval", "updateInterval", 2), |
| 155 |
] |
| 156 |
helpers.convert_mapping_to_xml(root, data, mapping, fail_required=True) |
| 157 |
|
| 158 |
# Required - complex |
| 159 |
sorting_val = data.get("sorting", "none") |
| 160 |
sorting_map = { |
| 161 |
"none": "None", |
| 162 |
"title": ("se.diabol.jenkins.pipeline.sort.NameComparator"), |
| 163 |
"failed_last_activity": ( |
| 164 |
"se.diabol.jenkins.pipeline.sort.FailedJobComparator" |
| 165 |
), |
| 166 |
"last_activity": ( |
| 167 |
"se.diabol.jenkins.pipeline.sort.LatestActivityComparator" |
| 168 |
), |
| 169 |
} |
| 170 |
sorting = XML.SubElement(root, "sorting") |
| 171 |
|
| 172 |
if sorting_val in sorting_map: |
| 173 |
sorting.text = sorting_map[sorting_val] |
| 174 |
else: |
| 175 |
sorting.text = sorting_map["none"] |
| 176 |
|
| 177 |
components = data.get("components", []) |
| 178 |
|
| 179 |
if len(components): |
| 180 |
component_specs = XML.SubElement(root, "componentSpecs") |
| 181 |
|
| 182 |
for c in components: |
| 183 |
component_spec = XML.SubElement( |
| 184 |
component_specs, |
| 185 |
"se.diabol.jenkins.pipeline.DeliveryPipelineView_-ComponentSpec", |
| 186 |
) |
| 187 |
|
| 188 |
name = XML.SubElement(component_spec, "name") |
| 189 |
name.text = c.get("name", "") |
| 190 |
|
| 191 |
first_job = XML.SubElement(component_spec, "firstJob") |
| 192 |
first_job.text = c.get("initial-job", "") |
| 193 |
|
| 194 |
last_job = XML.SubElement(component_spec, "lastJob") |
| 195 |
last_job.text = c.get("final-job", "") |
| 196 |
|
| 197 |
show_upstream = XML.SubElement(component_spec, "showUpstream") |
| 198 |
show_upstream.text = c.get("show-upstream", "false") |
| 199 |
|
| 200 |
regexps = data.get("regexps", []) |
| 201 |
|
| 202 |
if len(regexps): |
| 203 |
regexp_first_jobs = XML.SubElement(root, "regexpFirstJobs") |
| 204 |
|
| 205 |
for r in regexps: |
| 206 |
regexp_first_job = XML.SubElement( |
| 207 |
regexp_first_jobs, |
| 208 |
"se.diabol.jenkins.pipeline.DeliveryPipelineView_-RegExpSpec", |
| 209 |
) |
| 210 |
|
| 211 |
regexp = XML.SubElement(regexp_first_job, "regexp") |
| 212 |
regexp.text = r.get("regexp", "") |
| 213 |
|
| 214 |
show_upstream = XML.SubElement(regexp_first_job, "showUpstream") |
| 215 |
show_upstream.text = r.get("show-upstream", "false") |
| 216 |
|
| 217 |
return root |