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
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.
Below 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:
This is the conceptual building block I have answer here and can be tweak based on requirements.
Best worked in my case while deploying in multiple servers in one time.
NOTE: tags are removed from the image for privacy reasons.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With