Skip to content

Environment variables not passed other jobs with 'dependencies'

Summary

As opposed to documentation, environment variables are not passed to other jobs when explicit dependencies are in place.

Steps to reproduce

Below is the contents of the .gitlab-ci.yml to reproduce the issue. VERSION environment variable is not passed to jobs which have an explicit dependency to build stage. Those are labeled as does-not-work-x

image: node:15.14.0

stages:
    - build
    - push

build:
  stage: build
  script:
    - touch hello_bug.txt
  artifacts:
    paths:
      - hello_bug.txt

get-version:
  stage: build
  script:
    - VERSION=0.999
    - echo "VERSION=$VERSION"
    - echo "VERSION=$VERSION" >> build.env
  artifacts:
    reports:
      dotenv: build.env    

works-1-basic:
  environment: dev
  stage: push
  image: busybox
  script:
    - echo "VERSION=$VERSION"

works-2-rules:
  environment: dev
  stage: push
  image: busybox
  script:
    - echo "VERSION=$VERSION"
  rules:
    - if: $CI_COMMIT_BRANCH != "master"

works-3-except:
  environment: dev
  stage: push
  image: busybox
  script:
    - echo "VERSION=$VERSION"
  except:
    - master

does-not-work-1-dependencies:
  environment: dev
  stage: push
  image: busybox
  script:
    - echo "VERSION=$VERSION"
  dependencies:
    - build

does-not-work-2-dependencies-rules:
  environment: dev
  stage: push
  image: busybox
  script:
    - echo "VERSION=$VERSION"
  dependencies:
    - build
  rules:
    - if: $CI_COMMIT_BRANCH != "master"

does-not-work-3-dependencies-except:
  environment: dev
  stage: push
  image: busybox
  script:
    - echo "VERSION=$VERSION"
  dependencies:
    - build
  except:
    - master

What is the current bug behavior?

Environment variables are not passed to other jobs when explicit dependencies are in place.

What is the expected correct behavior?

Environment variables should be passed to other jobs when explicit dependencies are or not in place.