Search code examples
gitlabgitlab-cigitlab-ci-runner

.gitlab-ci stages execution order


I have this .gitlab-ci.yml file:

stepA:
  script:
    - echo "A"
deploy:
  script:
    - echo "1"
stepB:
  script:
    - echo "B"

How can I set which stage should be run in first ? Some jobs can be run in parallel by multiple gitlab runners. I just want to be sure step A to B are finished before running deploy stage


Solution

  • This is exactly what stages is for. You are using the word "stage" here when actually describing a "job".

    Jobs in the same stage may be run in parallel (if you have the runners to support it) but stages run in order.

    First define your 2 stages at the top level of the .gitlab-ci.yml:

    stages:
      - build
      - dist
    

    Then on each job, specify the stage it belongs to:

    stepA:
      stage: build
      script:
        - echo "A"
    deploy:
      stage: dist
      script:
        - echo "1"
    stepB:
      stage: build
      script:
        - echo "B"
    

    Now stepA and stepB will run first (in any order or even in parallel) followed by deploy provided the first stage succeeds.