scrapeureux
scrapeureux

Reputation: 61

Multiple extends or multiple stages?

I want to have a CI to deploy two commands ("bash X" and "bash Y") on different production servers (server 1, server 2, server 3, etc.).

I looked for multiple stages but it don't seems to answer my question. I don't really care if it runs in parallel or B after A. (the manual section is for debugging)

I don't know how to do it : I tried with multiple extends but it only takes the last one (bashB) in my pipeline.

stages:
  - get_password
  - bashA
  - bashB

get_password:
  stage: get_password

# Steps

.bashA:
  stage: bashA
  script:
    - lorem ipsum
  when: manual
  only:
    changes:
      - script/bashA.sh

.bashB:
  stage: bashB
  script:
    - ipsum loreem
  when: manual
  only:
    changes:
      - script/bashB.sh

# SRV1
deploy-srv1:
  extends: 
    - .bashA
    - .bashB
  variables:
    SRV_1: urlsrv1

# SRV2
deploy-srv2:
  extends: 
    - .bashA
    - .bashB
  variables:
    SRV_1: urlsrv2

I just want to be able to deploy bashA and bash B on X servers (I just took 2 servers for example).

Upvotes: 6

Views: 41520

Answers (1)

MrBerta
MrBerta

Reputation: 2748

When using multiple extend in GitLab, some of the values will not be merged, but overwritten. If you check the documentation here:

https://docs.gitlab.com/ee/ci/yaml/#extends

They write:

The algorithm used for merge is “closest scope wins”, so keys from the last member will always shadow anything defined on other levels

You are not alone in wanting a feature to be able to merge scripts instead of overwriting them. Here's an open issue on GitLab to do what you described:

https://gitlab.com/gitlab-org/gitlab/issues/16376

In the meantime, and only looking at the example you provided, you can get something like what you want by manually merging bashA and bashB into one job:

stages:
  - get_password
  - bash

get_password:
  stage: get_password

# Steps

.bash_both:
  stage: bash
  script:
    - lorem ipsum
    - ipsum loreem
  when: manual
  only:
    changes:
      - script/bashA.sh
      - script/bashB.sh

# SRV1
deploy-srv1:
  extends: 
    - .bash_both
  variables:
    SRV_1: urlsrv1

# SRV2
deploy-srv2:
  extends: 
    - .bash_both
  variables:
    SRV_1: urlsrv2

Upvotes: 11

Related Questions