Debian Codegraph @

jenkins_jobs/modules/project_flow.py

raw
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2013 eNovance SAS <[email protected]>
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
14 # under the License.
15
16
17 """
18 The flow Project module handles creating Jenkins flow projects.
19 You may specify ``flow`` in the ``project-type`` attribute of
20 the :ref:`Job` definition.
21
22 Requires the Jenkins :jenkins-plugins:`Build Flow Plugin <build-flow-plugin>`.
23
24 In order to use it for job-template you have to escape the curly braces by
25 doubling them in the DSL: { -> {{ , otherwise it will be interpreted by the
26 python str.format() command.
27
28 :Job Parameters:
29 * **dsl** (`str`): The DSL content. (optional)
30 * **needs-workspace** (`bool`): This build needs a workspace. \
31 (default false)
32 * **dsl-file** (`str`): Path to the DSL script in the workspace. \
33 Has effect only when `needs-workspace` is true. (optional)
34
35 Job example:
36
37 .. literalinclude::
38 /../../tests/yamlparser/job_fixtures/project_flow_template001.yaml
39
40 Job template example:
41
42 .. literalinclude::
43 /../../tests/yamlparser/job_fixtures/project_flow_template002.yaml
44
45 Job example runninng a DSL file from the workspace:
46
47 .. literalinclude::
48 /../../tests/yamlparser/job_fixtures/project_flow_template003.yaml
49
50 """
51
52 import xml.etree.ElementTree as XML
53
54 import jenkins_jobs.modules.base
55 from jenkins_jobs.modules.helpers import convert_mapping_to_xml
56
57
58 class Flow(jenkins_jobs.modules.base.Base):
59 sequence = 0
60
61 def root_xml(self, data):
62 xml_parent = XML.Element("com.cloudbees.plugins.flow.BuildFlow")
63
64 needs_workspace = data.get("needs-workspace", False)
65 mapping = [
66 ("dsl", "dsl", ""),
67 ("needs-workspace", "buildNeedsWorkspace", False),
68 ]
69 convert_mapping_to_xml(xml_parent, data, mapping, fail_required=True)
70 if needs_workspace and "dsl-file" in data:
71 XML.SubElement(xml_parent, "dslFile").text = data["dsl-file"]
72
73 return xml_parent