Search code examples
gitlabyamlgitlab-cipipeline

Append the script on one stage .gitlab-ci.yml


How to append the script section in one stage in the .gitlab-ci.yml file?

e.g in this example

stages:
  - stage1_name

.a:
  script:
    - echo "String 1"

.b:
  script:
    - echo "String 2"


stage1_name:
  stage: stage1_name
  extends: .a
  extends: .b
  script:
    - echo "String 3"

how to get as output:

String 1
String 2
String 3

instead of:

String 3

Solution

  • Gitlab 13.9 introduced a !reference-tag which makes this possible;

    .setup:
      script:
        - echo creating environment
    
    test:
      script:
        - !reference [.setup, script]
        - echo running my own command