diff --git a/jenkins_jobs/modules/project_flow.py b/jenkins_jobs/modules/project_flow.py index 6df824400..de652f9e2 100644 --- a/jenkins_jobs/modules/project_flow.py +++ b/jenkins_jobs/modules/project_flow.py @@ -25,6 +25,13 @@ In order to use it for job-template you have to escape the curly braces by doubling them in the DSL: { -> {{ , otherwise it will be interpreted by the python str.format() command. +:Job Parameters: + * **dsl** (`str`): The DSL content. (optional) + * **needs-workspace** (`bool`): This build needs a workspace. \ + (default false) + * **dsl-file** (`str`): Path to the DSL script in the workspace. \ + Has effect only when `needs-workspace` is true. (optional) + Job example: .. literalinclude:: @@ -35,6 +42,11 @@ Job template example: .. literalinclude:: /../../tests/yamlparser/fixtures/project_flow_template002.yaml +Job example runninng a DSL file from the workspace: + + .. literalinclude:: + /../../tests/yamlparser/fixtures/project_flow_template003.yaml + """ import xml.etree.ElementTree as XML @@ -51,4 +63,11 @@ class Flow(jenkins_jobs.modules.base.Base): else: XML.SubElement(xml_parent, 'dsl').text = '' + needs_workspace = data.get('needs-workspace', False) + XML.SubElement(xml_parent, 'buildNeedsWorkspace').text = str( + needs_workspace).lower() + + if needs_workspace and 'dsl-file' in data: + XML.SubElement(xml_parent, 'dslFile').text = data['dsl-file'] + return xml_parent diff --git a/tests/general/fixtures/project-type003.xml b/tests/general/fixtures/project-type003.xml index 8fadfac7a..bc26efddd 100644 --- a/tests/general/fixtures/project-type003.xml +++ b/tests/general/fixtures/project-type003.xml @@ -1,6 +1,7 @@ + false false false diff --git a/tests/yamlparser/fixtures/project_flow_template001.xml b/tests/yamlparser/fixtures/project_flow_template001.xml index 864a0e56c..33fd0bbee 100644 --- a/tests/yamlparser/fixtures/project_flow_template001.xml +++ b/tests/yamlparser/fixtures/project_flow_template001.xml @@ -6,6 +6,7 @@ parallel ( { build("job2b") } ) + false <!-- Managed by Jenkins Job Builder --> false diff --git a/tests/yamlparser/fixtures/project_flow_template002.xml b/tests/yamlparser/fixtures/project_flow_template002.xml index ac1973e1c..74f04ae66 100644 --- a/tests/yamlparser/fixtures/project_flow_template002.xml +++ b/tests/yamlparser/fixtures/project_flow_template002.xml @@ -7,6 +7,7 @@ parallel ( ) build("job2c") + false <!-- Managed by Jenkins Job Builder --> false diff --git a/tests/yamlparser/fixtures/project_flow_template003.xml b/tests/yamlparser/fixtures/project_flow_template003.xml new file mode 100644 index 000000000..0fedba697 --- /dev/null +++ b/tests/yamlparser/fixtures/project_flow_template003.xml @@ -0,0 +1,17 @@ + + + + true + script.groovy + + <!-- Managed by Jenkins Job Builder --> + false + false + false + false + true + + + + + diff --git a/tests/yamlparser/fixtures/project_flow_template003.yaml b/tests/yamlparser/fixtures/project_flow_template003.yaml new file mode 100644 index 000000000..391fea474 --- /dev/null +++ b/tests/yamlparser/fixtures/project_flow_template003.yaml @@ -0,0 +1,5 @@ +- job: + name: test_job + project-type: flow + needs-workspace: true + dsl-file: script.groovy