From d741ea02c6ea45357318b0d5ff759802e34ecf69 Mon Sep 17 00:00:00 2001 From: Vsevolod Fedorov Date: Mon, 4 Dec 2023 10:48:31 +0300 Subject: [PATCH] Task: 47875 Story: 2010711 Search for included files relative to the current job first Change-Id: I34a5743967bf7cbb8b464a0a36abad24180d61e4 Signed-off-by: Max Trunov --- jenkins_jobs/yaml_objects.py | 2 +- .../include_missing_path_in_j2_yaml.error | 2 +- .../regression-2010711/expected-output.xml | 40 +++++++++++++++++++ .../regression-2010711/job_1/job_1.yaml | 13 ++++++ .../regression-2010711/job_1/sample_file.sh | 1 + .../regression-2010711/job_2/job_2.yaml | 13 ++++++ .../regression-2010711/job_2/sample_file.sh | 1 + .../job_fixtures/regression-2010711/test.conf | 2 + 8 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 tests/yamlparser/job_fixtures/regression-2010711/expected-output.xml create mode 100644 tests/yamlparser/job_fixtures/regression-2010711/job_1/job_1.yaml create mode 100644 tests/yamlparser/job_fixtures/regression-2010711/job_1/sample_file.sh create mode 100644 tests/yamlparser/job_fixtures/regression-2010711/job_2/job_2.yaml create mode 100644 tests/yamlparser/job_fixtures/regression-2010711/job_2/sample_file.sh create mode 100644 tests/yamlparser/job_fixtures/regression-2010711/test.conf diff --git a/jenkins_jobs/yaml_objects.py b/jenkins_jobs/yaml_objects.py index 5ff2eb968..04bd1363f 100644 --- a/jenkins_jobs/yaml_objects.py +++ b/jenkins_jobs/yaml_objects.py @@ -248,7 +248,7 @@ class BaseYamlObject(metaclass=abc.ABCMeta): return cls(loader.jjb_config, loader, loader.pos_from_node(node), value) def __init__(self, jjb_config, loader, pos): - self._search_path = jjb_config.yamlparser["include_path"] + self._search_path = jjb_config.yamlparser["include_path"].copy() if loader.source_dir: # Loaded from a file, find includes beside it too. self._search_path.append(loader.source_dir) diff --git a/tests/yamlparser/error_fixtures/include_missing_path_in_j2_yaml.error b/tests/yamlparser/error_fixtures/include_missing_path_in_j2_yaml.error index 9b3c67bb8..21c40bd8d 100644 --- a/tests/yamlparser/error_fixtures/include_missing_path_in_j2_yaml.error +++ b/tests/yamlparser/error_fixtures/include_missing_path_in_j2_yaml.error @@ -7,6 +7,6 @@ include_missing_path_in_j2_yaml.yaml:3:3: In job template 'sample-job' include_missing_path_in_j2_yaml.yaml:5:15: In expanded !j2-yaml: builders: !j2-yaml: | ^ -:2:5: File missing-file.sh does not exist in any of include directories: .,fixtures-dir,fixtures-dir +:2:5: File missing-file.sh does not exist in any of include directories: .,fixtures-dir !include: missing-file.sh ^ diff --git a/tests/yamlparser/job_fixtures/regression-2010711/expected-output.xml b/tests/yamlparser/job_fixtures/regression-2010711/expected-output.xml new file mode 100644 index 000000000..1f736575b --- /dev/null +++ b/tests/yamlparser/job_fixtures/regression-2010711/expected-output.xml @@ -0,0 +1,40 @@ + + + + sample-job-1<!-- Managed by Jenkins Job Builder --> + false + false + false + false + true + + + + + echo sample_file 1 + + + + + + + + + + sample-job-2<!-- Managed by Jenkins Job Builder --> + false + false + false + false + true + + + + + echo sample_file 2 + + + + + + diff --git a/tests/yamlparser/job_fixtures/regression-2010711/job_1/job_1.yaml b/tests/yamlparser/job_fixtures/regression-2010711/job_1/job_1.yaml new file mode 100644 index 000000000..661bc1e41 --- /dev/null +++ b/tests/yamlparser/job_fixtures/regression-2010711/job_1/job_1.yaml @@ -0,0 +1,13 @@ +# https://storyboard.openstack.org/#!/story/2010711 +# Bug: Wrong files adding by tag !include-raw(include-raw-escape, etc) + +- job-template: + name: sample-job-1 + description: sample-job-1 + builders: + - shell: !include-raw-escape: sample_file.sh + +- project: + name: sample-project-1 + jobs: + - sample-job-1 diff --git a/tests/yamlparser/job_fixtures/regression-2010711/job_1/sample_file.sh b/tests/yamlparser/job_fixtures/regression-2010711/job_1/sample_file.sh new file mode 100644 index 000000000..cb3c5f7c1 --- /dev/null +++ b/tests/yamlparser/job_fixtures/regression-2010711/job_1/sample_file.sh @@ -0,0 +1 @@ +echo sample_file 1 diff --git a/tests/yamlparser/job_fixtures/regression-2010711/job_2/job_2.yaml b/tests/yamlparser/job_fixtures/regression-2010711/job_2/job_2.yaml new file mode 100644 index 000000000..a7a1ee4bd --- /dev/null +++ b/tests/yamlparser/job_fixtures/regression-2010711/job_2/job_2.yaml @@ -0,0 +1,13 @@ +# https://storyboard.openstack.org/#!/story/2010711 +# Bug: Wrong files adding by tag !include-raw(include-raw-escape, etc) + +- job-template: + name: sample-job-2 + description: sample-job-2 + builders: + - shell: !include-raw-escape: sample_file.sh + +- project: + name: sample-project-2 + jobs: + - sample-job-2 diff --git a/tests/yamlparser/job_fixtures/regression-2010711/job_2/sample_file.sh b/tests/yamlparser/job_fixtures/regression-2010711/job_2/sample_file.sh new file mode 100644 index 000000000..fac0dad00 --- /dev/null +++ b/tests/yamlparser/job_fixtures/regression-2010711/job_2/sample_file.sh @@ -0,0 +1 @@ +echo sample_file 2 diff --git a/tests/yamlparser/job_fixtures/regression-2010711/test.conf b/tests/yamlparser/job_fixtures/regression-2010711/test.conf new file mode 100644 index 000000000..f1fd8770d --- /dev/null +++ b/tests/yamlparser/job_fixtures/regression-2010711/test.conf @@ -0,0 +1,2 @@ +[job_builder] +recursive=True