I have the following jobs configuration in .gitlab-ci.yml
:
job1:
stage: test
services:
- name: mariadb
alias: mysql
entrypoint: [""]
command: [...]
script:
- ...
job2:
stage: test
services:
- name: mariadb
alias: mysql
entrypoint: [""]
command: [...]
script:
- ...
job3:
stage: test
services:
- name: mariadb
alias: mysql
entrypoint: [""]
command: [...]
script:
- ...
services
portion is the same for all 3 jobs.
Is it possible to avoid this duplication?
You can also utilize Anchors YAML feature - https://docs.gitlab.com/ee/ci/yaml/#anchors .
.job_template: &job_definition
services:
- name: mariadb
alias: mysql
entrypoint: [""]
command: [...]
job1:
<<: *job_definition
stage: test
When the config is common for all jobs, use global service. When you want to avoid duplication among only some jobs, use YAML anchors.
Just define it outside the jobs: https://docs.gitlab.com/ce/ci/docker/using_docker_images.html#define-image-and-services-from-gitlab-ci-yml
services:
- name: mariadb
alias: mysql
entrypoint: [""]
command: [...]
job1:
stage: test
script:
- ...
job2:
stage: test
script:
- ...
job3:
stage: test
script:
- ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With