Dynamic branch name for a downstream job in Gitlab CI/CD

trigger-job:
stage: deploy
trigger: my/app-path
branch: my-branch

1) Passing the branch name with custom environnement variables

Use the global keywork variable to pass the branch name to your downstream job.

variables:
MY_APP_BRANCH: new-feature
trigger-job:
stage: deploy
trigger: my/app-path
branch: $MY_APP_BRANCH

2) Using a job to pass environment variables to other jobs

This solutions will probably better suit your needs. The idea is to create a job that will create a dotenvreport artifact that will be automatically loaded by the trigger job.

job-to-pass-var:
script:
- echo "MY_APP_BRANCH=my-dynamic-branch-name" >> build.env
artifacts:
reports:
dotenv: build.env
trigger-job:
stage: deploy
trigger: my/app-path
branch: $MY_APP_BRANCH

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store