diff --git a/jenkins_jobs/yaml_objects.py b/jenkins_jobs/yaml_objects.py index f27642441..88c2447f6 100644 --- a/jenkins_jobs/yaml_objects.py +++ b/jenkins_jobs/yaml_objects.py @@ -143,34 +143,21 @@ For all the multi file includes, the files are simply appended using a newline character. -To allow for job templates to perform substitution on the path names, when a -filename containing a python format placeholder is encountered, lazy loading -support is enabled, where instead of returning the contents back during yaml -parsing, it is delayed until the variable substitution is performed. +You can also use variables in included file paths. Example: .. literalinclude:: /../../tests/yamlparser/job_fixtures/lazy-load-jobs001.yaml + with variable substitution inside included files: + + .. literalinclude:: /../../tests/yamlparser/job_fixtures/lazy-load-with-variables.yaml + using a list of files: .. literalinclude:: /../../tests/yamlparser/job_fixtures/lazy-load-jobs-multi001.yaml -.. note:: - - Because lazy-loading involves performing the substitution on the file - name, it means that jenkins-job-builder can not call the variable - substitution on the contents of the file. This means that the - ``!include-raw:`` tag will behave as though ``!include-raw-escape:`` tag - was used instead whenever name substitution on the filename is to be - performed. - - Given the behaviour described above, when substitution is to be performed - on any filename passed via ``!include-raw-escape:`` the tag will be - automatically converted to ``!include-raw:`` and no escaping will be - performed. - The tag ``!include-jinja2:`` will treat the given string or list of strings as filenames to be opened as Jinja2 templates, which should be rendered to a diff --git a/tests/yamlparser/job_fixtures/lazy-load-scripts/subst_vars_1.1.sh b/tests/yamlparser/job_fixtures/lazy-load-scripts/subst_vars_1.1.sh new file mode 100644 index 000000000..16d3c275b --- /dev/null +++ b/tests/yamlparser/job_fixtures/lazy-load-scripts/subst_vars_1.1.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# +# Version 1.1 of the subst vars script. + +echo branch={branch} diff --git a/tests/yamlparser/job_fixtures/lazy-load-scripts/subst_vars_1.2.sh b/tests/yamlparser/job_fixtures/lazy-load-scripts/subst_vars_1.2.sh new file mode 100644 index 000000000..b15156372 --- /dev/null +++ b/tests/yamlparser/job_fixtures/lazy-load-scripts/subst_vars_1.2.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# +# Version 1.2 of the subst vars script. + +echo branch={branch} diff --git a/tests/yamlparser/job_fixtures/lazy-load-with-variables.xml b/tests/yamlparser/job_fixtures/lazy-load-with-variables.xml new file mode 100644 index 000000000..247d6fba1 --- /dev/null +++ b/tests/yamlparser/job_fixtures/lazy-load-with-variables.xml @@ -0,0 +1,48 @@ + + + + <!-- Managed by Jenkins Job Builder --> + false + false + false + false + true + + + + + #!/bin/bash +# +# Version 1.1 of the subst vars script. + +echo branch=master + + + + + + + + + + <!-- Managed by Jenkins Job Builder --> + false + false + false + false + true + + + + + #!/bin/bash +# +# Version 1.2 of the subst vars script. + +echo branch=feature + + + + + + diff --git a/tests/yamlparser/job_fixtures/lazy-load-with-variables.yaml b/tests/yamlparser/job_fixtures/lazy-load-with-variables.yaml new file mode 100644 index 000000000..8ed7f4916 --- /dev/null +++ b/tests/yamlparser/job_fixtures/lazy-load-with-variables.yaml @@ -0,0 +1,18 @@ +# Variables should be substituted in included raw files +# when their path themselves contains variables. + +- job-template: + name: 'sample-job-{version}' + builders: + - shell: + !include-raw: lazy-load-scripts/subst_vars_{version}.sh + +- project: + name: sample-project + branch: master + version: + - 1.1 + - 1.2: + branch: feature + jobs: + - 'sample-job-{version}'