Debian Codegraph @

jenkins_jobs/modules/project_workflow.py

raw
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2015 David Caro <[email protected]>
3 #
4 # Based on jenkins_jobs/modules/project_flow.py by
5 # Copyright (C) 2013 eNovance SAS <[email protected]>
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 # http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16 # License for the specific language governing permissions and limitations
17 # under the License.
18
19
20 """
21 Deprecated: please use :ref:`project_pipeline` instead.
22
23 The workflow Project module handles creating Jenkins workflow projects.
24 You may specify ``workflow`` in the ``project-type`` attribute of
25 the :ref:`Job` definition.
26 For now only inline scripts are supported.
27
28 Requires the Jenkins :jenkins-plugins:`Workflow Plugin <workflow-aggregator>`.
29
30 In order to use it for job-template you have to escape the curly braces by
31 doubling them in the DSL: { -> {{ , otherwise it will be interpreted by the
32 python str.format() command.
33
34 :Job Parameters:
35 * **dsl** (`str`): The DSL content.
36 * **sandbox** (`bool`): If the script should run in a sandbox (default
37 false)
38
39 Job example:
40
41 .. literalinclude::
42 /../../tests/yamlparser/job_fixtures/project_workflow_template001.yaml
43
44 Job template example:
45
46 .. literalinclude::
47 /../../tests/yamlparser/job_fixtures/project_workflow_template002.yaml
48
49 """
50 import logging
51 import xml.etree.ElementTree as XML
52
53 import jenkins_jobs.modules.base
54 import jenkins_jobs.modules.helpers as helpers
55
56
57 class Workflow(jenkins_jobs.modules.base.Base):
58 sequence = 0
59
60 def root_xml(self, data):
61 logger = logging.getLogger(__name__)
62 logger.warning("Workflow job type is deprecated, please use Pipeline job type")
63
64 xml_parent = XML.Element("flow-definition", {"plugin": "workflow-job"})
65 xml_definition = XML.SubElement(
66 xml_parent,
67 "definition",
68 {
69 "class": "org.jenkinsci.plugins." "workflow.cps.CpsFlowDefinition",
70 "plugin": "workflow-cps",
71 },
72 )
73
74 mapping = [("dsl", "script", None), ("sandbox", "sandbox", False)]
75 helpers.convert_mapping_to_xml(
76 xml_definition, data, mapping, fail_required=True
77 )
78
79 return xml_parent