How to run multiple stages in the same container in gitlab?

Viewed 1394

I've 3 stages:

- provision
- cpp tests
- python tests

I need to run provision before running tests. Gitlab suggests using artifacts to pass result between stages but I'm afraid it's not possible in my scenario since ansible does lots of different stuff (not just generate a few config files/binaries). Ideally, I'd like to be able to run all three stages in the same container because in my scenario stages are logical and essentially can be merged into one. I'd want to avoid it as this would make .gitlab-ci.yml harder to understand.

1 Answers

If you have 3 tasks which can be merged into one and what you want to achieve is only to have 3 separated functions running in the same container to make the .gitlab-ci.yml file easier to understand, I would recommend using yaml anchors (see below).

.provision_template: &provision_definition
    - XXX

.cpp_tests_template: &cpp_tests_definition
    - YYY

.python_tests_template: &python_tests_definition
    - ZZZ

my_job:
  script:
    - *provision_definition
    - *cpp_tests_definition
    - *python_tests_definition
Related