Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.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

like image 769
Bob5421 Avatar asked Apr 20 '26 16:04

Bob5421


2 Answers

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.

like image 162
SpencerPark Avatar answered Apr 25 '26 03:04

SpencerPark


enter image description hereBelow code uses in inheritance

Stages:
  - Step-A
  - Step-B
  - Deploy

.Perform-Step-A:
  stage: Step-A
  script:
   - echo "A"

.Perform-Step-B:
  stage: Step-B
  script:
   - echo "B"

.Perform-Deploy:
  stage: Deploy
  script:
   - echo "1"

Server1-Step-A:
  extends: .Perform-Step-A
  tags: Server-1-As-Runner //Else add SSH steps in Perfrom-A block

Server1-Step-B:
  extends: .Perform-Step-B
  tags: Server-1-As-Runner //Else add SSH steps in Perfrom-B block

Server1-Step-Deploy:
  extends: .Perform-Deploy
  tags: Server-1-As-Runner //Else add SSH steps in Perfrom-Deploy block

Assumptions:

  1. You are using dedicated runners for your application and runners configured on same machine. If not please feel free to modify and ssh steps.
  2. This is the conceptual building block I have answer here and can be tweak based on requirements.

  3. Best worked in my case while deploying in multiple servers in one time.

NOTE: tags are removed from the image for privacy reasons.

like image 27
Akshay barahate Avatar answered Apr 25 '26 04:04

Akshay barahate



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!