| 1 |
# Copyright 2015 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 pipeline module handles creating Jenkins Build Pipeline views. |
| 17 |
To create a pipeline view specify ``pipeline`` in the ``view-type`` attribute |
| 18 |
to the :ref:`view_pipeline` definition. |
| 19 |
|
| 20 |
Requires the Jenkins :jenkins-plugins:`Build Pipeline Plugin |
| 21 |
<build-pipeline-plugin>`. |
| 22 |
|
| 23 |
:View Parameters: |
| 24 |
* **name** (`str`): The name of the view. |
| 25 |
* **view-type** (`str`): The type of view. |
| 26 |
* **description** (`str`): A description of the view. (optional) |
| 27 |
* **filter-executors** (`bool`): Show only executors that can |
| 28 |
execute the included views. (default false) |
| 29 |
* **filter-queue** (`bool`): Show only included jobs in builder |
| 30 |
queue. (default false) |
| 31 |
* **first-job** (`str`): Parent Job in the view. |
| 32 |
* **no-of-displayed-builds** (`str`): Number of builds to display. |
| 33 |
(default 1) |
| 34 |
* **title** (`str`): Build view title. (optional) |
| 35 |
* **linkStyle** (`str`): Console output link style. Can be |
| 36 |
'Lightbox', 'New Window', or 'This Window'. (default Lightbox) |
| 37 |
* **css-Url** (`str`): Url for Custom CSS files (optional) |
| 38 |
* **latest-job-only** (`bool`) Trigger only latest job. |
| 39 |
(default false) |
| 40 |
* **manual-trigger** (`bool`) Always allow manual trigger. |
| 41 |
(default false) |
| 42 |
* **show-parameters** (`bool`) Show pipeline parameters. |
| 43 |
(default false) |
| 44 |
* **parameters-in-headers** (`bool`) Show pipeline parameters in |
| 45 |
headers. (default false) |
| 46 |
* **starts-with-parameters** (`bool`) Use Starts with parameters. |
| 47 |
(default false) |
| 48 |
* **refresh-frequency** (`str`) Frequency to refresh in seconds. |
| 49 |
(default '3') |
| 50 |
* **definition-header** (`bool`) Show pipeline definition header. |
| 51 |
(default false) |
| 52 |
|
| 53 |
Example: |
| 54 |
|
| 55 |
.. literalinclude:: |
| 56 |
/../../tests/views/fixtures/view_pipeline001.yaml |
| 57 |
|
| 58 |
Example: |
| 59 |
|
| 60 |
.. literalinclude:: |
| 61 |
/../../tests/views/fixtures/view_pipeline002.yaml |
| 62 |
""" |
| 63 |
|
| 64 |
import xml.etree.ElementTree as XML |
| 65 |
import jenkins_jobs.modules.base |
| 66 |
import jenkins_jobs.modules.helpers as helpers |
| 67 |
|
| 68 |
|
| 69 |
class Pipeline(jenkins_jobs.modules.base.Base): |
| 70 |
sequence = 0 |
| 71 |
|
| 72 |
def root_xml(self, data): |
| 73 |
linktypes = ["Lightbox", "New Window"] |
| 74 |
root = XML.Element( |
| 75 |
"au.com.centrumsystems.hudson." "plugin.buildpipeline.BuildPipelineView", |
| 76 |
{"plugin": "build-pipeline-plugin"}, |
| 77 |
) |
| 78 |
|
| 79 |
mapping_optional = [ |
| 80 |
("description", "description", None), |
| 81 |
("filter-executors", "filterExecutors", False), |
| 82 |
("filter-queue", "filterQueue", False), |
| 83 |
] |
| 84 |
helpers.convert_mapping_to_xml( |
| 85 |
root, data, mapping_optional, fail_required=False |
| 86 |
) |
| 87 |
|
| 88 |
XML.SubElement(root, "properties", {"class": "hudson.model.View$PropertyList"}) |
| 89 |
|
| 90 |
GBurl = ( |
| 91 |
"au.com.centrumsystems.hudson.plugin.buildpipeline." |
| 92 |
"DownstreamProjectGridBuilder" |
| 93 |
) |
| 94 |
gridBuilder = XML.SubElement(root, "gridBuilder", {"class": GBurl}) |
| 95 |
|
| 96 |
jobname = data.get("first-job", "") |
| 97 |
XML.SubElement(gridBuilder, "firstJob").text = jobname |
| 98 |
|
| 99 |
mapping = [ |
| 100 |
("name", "name", None), |
| 101 |
("no-of-displayed-builds", "noOfDisplayedBuilds", 1), |
| 102 |
("title", "buildViewTitle", ""), |
| 103 |
("link-style", "consoleOutputLinkStyle", "Lightbox", linktypes), |
| 104 |
("css-Url", "cssUrl", ""), |
| 105 |
("latest-job-only", "triggerOnlyLatestJob", False), |
| 106 |
("manual-trigger", "alwaysAllowManualTrigger", False), |
| 107 |
("show-parameters", "showPipelineParameters", False), |
| 108 |
("parameters-in-headers", "showPipelineParametersInHeaders", False), |
| 109 |
("start-with-parameters", "startsWithParameters", False), |
| 110 |
("refresh-frequency", "refreshFrequency", 3), |
| 111 |
("definition-header", "showPipelineDefinitionHeader", False), |
| 112 |
] |
| 113 |
helpers.convert_mapping_to_xml(root, data, mapping, fail_required=True) |
| 114 |
|
| 115 |
return root |