lemoncodes
lemoncodes

Reputation: 2421

GitLab CI/CD Multiple runners

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

Upvotes: 0

Views: 761

Answers (2)

zm31
zm31

Reputation: 269

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.

Upvotes: 1

dvs
dvs

Reputation: 519

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.

Upvotes: 2

Related Questions