gitlab: preserve base rules for container template
PATCH 1/1 gitlab: preserve base rules for container template
When extending the container template to allow scheduled piplines in upstream context, we must ensure that all the existing rules defined by .base_job_template are preserved.
Fortunately since the new rule for scheduled pipelines can come at the head of all other rules, not in the middle, we can just the obscure '!reference' syntax to pull in all the pre-existing rules as a single block.
This fixes
* stable branches using the wrong tag name in container images
* pushes to forks unconditionally running container builds
--- .gitlab-ci.d/container-template.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
.gitlab-ci.d/container-template.yml +2 -3
@@ -23,6 +23,5 @@ - docker logout rules: # because we want to enable this for scheduled runs we also have to replicate the normal rules - - if: '$CI_PIPELINE_SOURCE == "schedule"' - - if: '$CI_PROJECT_NAMESPACE == $QEMU_CI_UPSTREAM && $CI_COMMIT_BRANCH =~ /^staging/' - - if: '$QEMU_CI && $CI_PROJECT_NAMESPACE != $QEMU_CI_UPSTREAM' + - if: '$CI_PIPELINE_SOURCE == "schedule" && $CI_PROJECT_NAMESPACE == $QEMU_CI_UPSTREAM' + - !reference [.base_job_template, rules]
Signature · 1 line
2.52.0
Quoted 9 lines · Daniel P. Berrangé
When extending the container template to allow scheduled piplines in upstream context, we must ensure that all the existing rules defined by .base_job_template are preserved.
Fortunately since the new rule for scheduled pipelines can come at the head of all other rules, not in the middle, we can just the obscure '!reference' syntax to pull in all the pre-existing rules as a single block.
Quoted 4 lines
This fixes
* stable branches using the wrong tag name in container images
* pushes to forks unconditionally running container builds
I wont pretend I know what "!reference" means in yaml. But this change seems to fix both issues, and does not look like it breaks something.
Quoted 1 line
Fixes 8bec7b9874235e60f14172618121c60fdbd39302
Thanks!
/mjt
Quoted 10 lines · Michael Tokarev
Quoted 9 lines · Daniel P. Berrangé
When extending the container template to allow scheduled piplines in upstream context, we must ensure that all the existing rules defined by .base_job_template are preserved.
Fortunately since the new rule for scheduled pipelines can come at the head of all other rules, not in the middle, we can just the obscure '!reference' syntax to pull in all the pre-existing rules as a single block.
Quoted 8 lines
Quoted 4 lines
This fixes
* stable branches using the wrong tag name in container images
* pushes to forks unconditionally running container buildsI wont pretend I know what "!reference" means in yaml. But this change seems to fix both issues, and does not look like it breaks something.
Think of it as a symlink to the "rules" definition in the ".base_job_template":
https://docs.gitlab.com/ci/yaml/yaml_optimization/#reference-tags
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|