Post

How to transfer gitlab calculated variable into trigger section

How to pass a dynamically calculated variable from one GitLab CI job to a downstream trigger job using dotenv artifacts.

One has to use the artifacts section combined with the reports child keyword and save a variable with its value to a build.env file. The downstream trigger job can then reference these variables. This pattern is essential when you need to pass dynamically computed values (like version numbers) between pipeline stages. https://techhelpnotes.com/gitlab-ci-pass-variable-to-a-trigger-stage/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
create_profile:
  stage: build
  script:
  # calculate APPLICATION_VERSION
    - echo APPLICATION_VERSION=0.1.0 >> build.env
    - echo Create profile ${APPLICATION_NAME} with version ${APPLICATION_VERSION}
  artifacts:
    paths:
      - profile
    reports:
      dotenv: build.env

trigger_upload:
  stage: release
  variables:
    PROFILE_NAME: ${APPLICATION_NAME}
    PROFILE_VERSION: ${APPLICATION_VERSION}
  trigger:
    project: git-project/profile-uploader
    strategy: depend
  needs:
    - job: create_profile
      artifacts: true
This post is licensed under CC BY 4.0 by the author.