Gitlab CI Skip Jobs if Variable is set

  • skip the build jobs if the $DEPLOY variable is set
  • run manual jobs if the $DEPLOY variable is set
stages:
  - build
  - deploy
 
.deploy:
  allow_failure: true
  rules:
  - if: *on-master
    when: manual
  script:
    - echo "Deploying application..."
    - echo "Application successfully deployed."
 
## jobs
 
build:
  stage: build
  rules:
    # skip stages in deploy pipelines
  - if: $DEPLOY
    when: never
  script:
    - echo "Building Backend..."
    - echo "Build complete."
 
deploy:
  extends: .deploy
  stage: deploy-dev
  environment: dev
  rules:
  - if: $DEPLOY == 'dev'
    when: always