Search code examples
continuous-integrationgitlabgitlab-cipipelinejobs

Stop running jobs in parallel Gitlab CI


Is there any way to stop jobs running in parallel in gitlab CI? My gitlab-ci.yml file is:

image: google/cloud-sdk:slim

stages: 
  - deploy

before_script:
  - echo $ENVIRONMENT
  - gcloud auth activate-service-account --key-file $GOOGLE_SERVICE_ACCOUNT_FILE
  - gcloud config set project $GOOGLE_PROJECT_ID

deploy_website:
  stage: deploy
  script:
    - sed -i -e 's/https:\/\/us-central1-ahinko-website.cloudfunctions.net\/send_contact'/$GOOGLE_CLOUD_FUNCTION_EMAIL_URL'/g' src/client-side/js/custom-script.js
    - gsutil -m rm $GOOGLE_CLOUD_BUCKET/**
    - gsutil -m cp -R src/client-side/* $GOOGLE_CLOUD_BUCKET
  environment:
    name: $ENVIRONMENT

deploy_cloud_function: 
  stage: deploy
  script:
    - gcloud functions deploy send_contact --entry-point=send_contact_form --ingress-settings=all --runtime=python37 --source=src/server-side/cf-send-email/ --trigger-http
  when: on_success
  environment:
    name: $ENVIRONMENT

Both runs in parallel, and i don't want in this way.. jobs running in parallel


Solution

  • Use stages: they will be executed in the order defined in the stages declaration.

    image: google/cloud-sdk:slim
    
    stages: 
      - deploy
      - cloud
    
    before_script:
      - echo $ENVIRONMENT
      - gcloud auth activate-service-account --key-file $GOOGLE_SERVICE_ACCOUNT_FILE
      - gcloud config set project $GOOGLE_PROJECT_ID
    
    deploy_website:
      stage: deploy
      script:
        - sed -i -e 's/https:\/\/us-central1-ahinko-website.cloudfunctions.net\/send_contact'/$GOOGLE_CLOUD_FUNCTION_EMAIL_URL'/g' src/client-side/js/custom-script.js
        - gsutil -m rm $GOOGLE_CLOUD_BUCKET/**
        - gsutil -m cp -R src/client-side/* $GOOGLE_CLOUD_BUCKET
      environment:
        name: $ENVIRONMENT
    
    deploy_cloud_function: 
      stage: cloud
      script:
        - gcloud functions deploy send_contact --entry-point=send_contact_form --ingress-settings=all --runtime=python37 --source=src/server-side/cf-send-email/ --trigger-http
      when: on_success
      environment:
        name: $ENVIRONMENT