Add support for a job-level `env` keyword
Summary
Steps require an explicitly defined environment. They don't inherit the CI variables (except legacy script translations).
Goals
So we need a job-level env
keyword as well, which applies to run
, setup
and teardown
.
Design
E.g. This is how we would pass pipeline id to steps as an environment variable:
my-job:
env:
MY_PIPELINE_ID: "${CI_PIPELINE_ID}"
run:
- step: gitlab.com/gitlab-org/ci-cd/runner-tools/echo-step#git@v1
inputs:
echo: My pipeline id: ${{ env.MY_PIPELINE_ID }}
Approach
This is how we should handle the env
key in Rails:
- It must be expanded / interpolated in Rails. This is different from the
run
,setup
andteardown
keywords becauseenv
references predefined variables. - The contents of
env
must be also stored and provided to runner. However runner will not pass them through byte-for-byte like steps. Instead, it will copy the env map into the gRPC run request as the initial environment: https://gitlab.com/gitlab-org/gitlab/-/blob/5b95c8f5a0eb84ad3571ba7333cd040bc628a69c/doc/architecture/blueprints/gitlab_steps/runner-integration.md?plain=1#L56