0
votes

im not sure if this has already been indicated in the docs but i want to know if this is possible

i have 2 runners (1 for building, and 1 for deploying) i have my .gitlab-ci.yml configured to run 2 jobs

job1 to build job2 to deploy

but currently both jobs run in parallel.

what i need is for job2 to wait for job1.

is the above scenario possible?

here is my sample .gitlab-ci.yml

job1: 
  tags: 
    - test1
  script:
    - echo Starting test build
    - ./mvnw clean package -DskipTest
  before_script:
    - cd backend
    - chmod +x mvnw

job2: 
  tags: 
    - deploy
  script:
    - echo Deployment Test
  before_script:
    - echo Pre-Deployment scripts running

thanks

2

2 Answers

2
votes

Define 'stages' for the jobs.

stages:
  - job1
  - job2

job1: 
  tags: 
    - test1
  script:
    - echo Starting test build
    - ./mvnw clean package -DskipTest
  before_script:
    - cd backend
    - chmod +x mvnw

job2: 
  tags: 
    - deploy
  script:
    - echo Deployment Test
  before_script:
    - echo Pre-Deployment scripts running

More details in the documentation.

1
votes

Try using the "needs" keyword in combination with unique runner tags.

job1: 
  tags: 
    - test1
  script:
    - echo Starting test build
    - ./mvnw clean package -DskipTest
  before_script:
    - cd backend
    - chmod +x mvnw

job2: 
  tags: 
    - deploy
  script:
    - echo Deployment Test
  before_script:
    - echo Pre-Deployment scripts running
  needs: ["job1"]

This is the ideal solution as it bypasses the priority of stages and therefore can be used in combination with any stages you actually might have associated with your pipelines. This option allows more flexibility in more complex (including multi project/pipeline) configurations.