Conditional statements in the script

Hi @johnprocter

This post might be useful to you, in terms of the syntax.

Also, you might want to use $CI_COMMIT_REF_SLUG rather than ..._NAME.

From your example code it’s not quite clear how you’re intending this job to be structured, but if you can it would be neater to use rules here:

.rules-staging: &rules-staging
    rules:
        - if: '$CI_COMMIT_BRANCH =~ /^staging\/[a-zA-Z0-9-\.]+$/'
          when: on_success
        - when: never

.rules-production: &rules-production
    rules:
        - if: '$CI_COMMIT_BRANCH == '$CI_DEFAULT_BRANCH'
          when: on_success
        - when: never

.my-ci-step: &my-ci-step
  image: 676020893150.dkr.ecr.us-east-1.amazonaws.com/rust:nightly-20201001
  stage: check
  allow_failure: false
  dependencies:
    - install
    - build
  script:
    - export PATH=$PATH:.cargo/bin
    - RUST_LOG=info [run some shell command]

my-ci-step:staging:
  <<: *rules-staging
  <<: *my-ci-step

mymy-ci-step:staging:
  <<: *rules-production
  <<: *my-ci-step
  before_script:
    - RUST_LOG=info [run some shell command]

If you can’t sensibly use before_script, then potentially you could split this job into separate stages.