Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we add a new stage in .gitlab-ci other than the stages from the template file

I have a template file which has few stages like:

template.yaml

stages:
    - a2
    - a3

Now, I have another file .gitlab-ci.yaml which should include stages from above template file, but also needs few more stages:

include:
  - project: 'path to repo'
    ref: main
    file: "/template.yml"

stages:
  - a1

job1:
   stage: a1

job2:
  stage: a2

I get the following error:

 chosen stage does not exist; available stages are .pre, a1, .post

Is it possible to do something similar without making any changes in the template file ?

like image 776
Marcelo BD Avatar asked Oct 25 '25 08:10

Marcelo BD


1 Answers

Gitlab does not support merging of arrays, likely since it would have no idea which order the merged array is supposed to be in: https://docs.gitlab.com/ee/ci/yaml/includes.html#override-included-configuration-arrays

Therefore, you just need to manually include the full contents of any arrays that you are redefining. For your example:

include:
  - project: 'path to repo'
    ref: main
    file: "/template.yml"

stages:
  - a1
  - a2
  - a3

job1:
   stage: a1

job2:
  stage: a2
like image 170
Tan Qi En Avatar answered Oct 26 '25 22:10

Tan Qi En



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!