diff --git a/jenkins_jobs/expander.py b/jenkins_jobs/expander.py index fed2f51f3..034f41dfe 100644 --- a/jenkins_jobs/expander.py +++ b/jenkins_jobs/expander.py @@ -11,7 +11,7 @@ # under the License. from functools import partial - +from itertools import filterfalse from jinja2 import StrictUndefined from .errors import Context, JenkinsJobsException @@ -255,7 +255,7 @@ def expand_parameters(expander, param_dict): required_params = list(enum_required_params(format, value_pos)) deps[name] = (key_pos, value_pos) try: - params = LocDict() + params = LocDict.merge(expanded_params) for n in required_params: v, kp, vp = expand(n) params.set_item(n, v, kp, vp) @@ -272,6 +272,7 @@ def expand_parameters(expander, param_dict): expanded_params.set_item(name, value, key_pos, value_pos) return (value, key_pos, value_pos) - for name in param_dict: + expand("name") # expand 'name' parameter first + for name in filterfalse(lambda x: x == "name", param_dict): expand(name) return expanded_params diff --git a/tests/yamlparser/job_fixtures/include03.xml b/tests/yamlparser/job_fixtures/include03.xml new file mode 100644 index 000000000..307402c3f --- /dev/null +++ b/tests/yamlparser/job_fixtures/include03.xml @@ -0,0 +1,166 @@ + + + + Gerrit Jenkins job listening for code review related events for acc-cdi project. +<!-- ['NGCP-project'] --> +<!-- Managed by Jenkins Job Builder --> + false + false + false + false + true + true + + + + + + *_parameters.txt + true + false + true + true + true + false + false + + + false + false + + true + true + true + true + true + true + true + + + + + false + + + false + + + + + + + + Default tests job +<!-- ['NGCP-project'] --> +<!-- Managed by Jenkins Job Builder --> + false + false + false + false + true + true + + + + acc-cdi-* + + + + + + + + + + + + docker_file=$docker_file +docker_tag=$docker_tag +docker_tag_ppa=$docker_tag_ppa +docker_push=$docker_push + + + + acc-cdi-manage-docker + ALWAYS + false + false + + + FAILURE + 2 + RED + true + + + UNSTABLE + 1 + YELLOW + true + + + FAILURE + 2 + RED + true + + + + + + + + + + + + + uuid=$uuid +release=$release +release_uuid=$release_uuid +branch=$branch +tag=$tag +distribution=$distribution +ppa=$ppa + + + + + acc-cdi-source + UNSTABLE_OR_BETTER + false + false + + + + + false + false + + true + true + true + true + true + true + true + + + + + false + + + false + + + + + false + + false + + + + + diff --git a/tests/yamlparser/job_fixtures/include03.yaml b/tests/yamlparser/job_fixtures/include03.yaml new file mode 100644 index 000000000..944d42157 --- /dev/null +++ b/tests/yamlparser/job_fixtures/include03.yaml @@ -0,0 +1,34 @@ +- defaults: + name: def + predefined-parameters: &predefined-parameters | + uuid=$uuid + release=$release + release_uuid=$release_uuid + branch=$branch + tag=$tag + distribution=$distribution + ppa=$ppa + predefined-docker-parameters: &predefined-docker-parameters | + docker_file=$docker_file + docker_tag=$docker_tag + docker_tag_ppa=$docker_tag_ppa + docker_push=$docker_push + +- _default_project: &default_project + name: default_project + jobs: + - '{name}-gerrit' + - '{name}-source-tests': &default_source-tests + tb: !include: include03_source-tests_trigger_builds.yaml.inc + tpb: !include: include03_source-tests_trigger_parameterized_builds.yaml.inc + lastjob: {} + labels: + - NGCP-project + +- job-template: !include: include03_gerrit.yaml.inc +- job-template: !include: include03_source-tests.yaml.inc +- job-template: !include: include03_manage-docker.yaml.inc + +- project: + name: acc-cdi + <<: *default_project diff --git a/tests/yamlparser/job_fixtures/include03_gerrit.yaml.inc b/tests/yamlparser/job_fixtures/include03_gerrit.yaml.inc new file mode 100644 index 000000000..d697dc79a --- /dev/null +++ b/tests/yamlparser/job_fixtures/include03_gerrit.yaml.inc @@ -0,0 +1,17 @@ +name: '{name}-gerrit' +project-type: freestyle +description: | + Gerrit Jenkins job listening for code review related events for {name} project. + +disabled: false +concurrent: true +publishers: + - archive: + artifacts: '*_parameters.txt' + allow-empty: true + fingerprint: true + - workspace-cleanup: + disable-deferred-wipeout: true +wrappers: + - workspace-cleanup + - timestamps diff --git a/tests/yamlparser/job_fixtures/include03_manage-docker.yaml.inc b/tests/yamlparser/job_fixtures/include03_manage-docker.yaml.inc new file mode 100644 index 000000000..25ab05b9f --- /dev/null +++ b/tests/yamlparser/job_fixtures/include03_manage-docker.yaml.inc @@ -0,0 +1,22 @@ +name: '{name}-manage-docker' +project-type: freestyle +description: | + build/tag/delete project docker image(s) + +disabled: false +concurrent: true +builders: + - copyartifact: + project: '{name}-get-code' + filter: 'source.tar.gz' + which-build: upstream-build + fallback-to-last-successful: false +publishers: + - workspace-cleanup: + disable-deferred-wipeout: true +wrappers: + - workspace-cleanup + - timestamps + - inject: + properties-content: | + PROJECTNAME={name} diff --git a/tests/yamlparser/job_fixtures/include03_source-tests.yaml.inc b/tests/yamlparser/job_fixtures/include03_source-tests.yaml.inc new file mode 100644 index 000000000..01b3906c5 --- /dev/null +++ b/tests/yamlparser/job_fixtures/include03_source-tests.yaml.inc @@ -0,0 +1,20 @@ +name: '{name}-source-tests' +project-type: freestyle +description: | + Default tests job + +properties: + - copyartifact: + projects: '{name}-*' +disabled: false +concurrent: true +builders: + - trigger-builds: '{obj:tb}' +publishers: + - trigger-parameterized-builds: '{obj:tpb}' + - workspace-cleanup: + disable-deferred-wipeout: true +wrappers: + - workspace-cleanup + - timestamps + - inject: '{obj:lastjob}' diff --git a/tests/yamlparser/job_fixtures/include03_source-tests_trigger_builds.yaml.inc b/tests/yamlparser/job_fixtures/include03_source-tests_trigger_builds.yaml.inc new file mode 100644 index 000000000..d1c0b935b --- /dev/null +++ b/tests/yamlparser/job_fixtures/include03_source-tests_trigger_builds.yaml.inc @@ -0,0 +1,5 @@ +- project: '{name}-manage-docker' + condition: UNSTABLE_OR_BETTER + block: true + current-parameters: CurrentBuildParameters + predefined-parameters: *predefined-docker-parameters diff --git a/tests/yamlparser/job_fixtures/include03_source-tests_trigger_parameterized_builds.yaml.inc b/tests/yamlparser/job_fixtures/include03_source-tests_trigger_parameterized_builds.yaml.inc new file mode 100644 index 000000000..5acedb9f3 --- /dev/null +++ b/tests/yamlparser/job_fixtures/include03_source-tests_trigger_parameterized_builds.yaml.inc @@ -0,0 +1,4 @@ +- project: '{name}-source' + condition: UNSTABLE_OR_BETTER + predefined-parameters: *predefined-parameters + current-parameters: CurrentBuildParameters