variables exported in before_script unavailable in after_script

Summary:

  • If you set a variable in the "before_script" of a job it is not available when calling the "after_script"

I can't see anything in the README (https://docs.gitlab.com/ee/ci/yaml/README.html) that suggests this is the expected behaviour.

Example:

stages:
  - demo

demo_job:
  stage: demo
  before_script:
    - export TEST_VAR=test_variable
    - echo $TEST_VAR is present
  script:
    - echo $TEST_VAR is present
  after_script:
    - echo $TEST_VAR is not present

Expected result:

  • Any variables exported in the before script should be available in both the script and after_script

Observed result: image

Possible related tickets/posts:

  • https://gitlab.com/gitlab-org/gitlab-ce/issues/32931 (this appears to be conflated with using variables within variables)
  • https://forum.gitlab.com/t/after-script-and-variables/3480 (forum post, hasn't been updated in a while)
Assignee Loading
Time tracking Loading