Expose Pipeline Environment Variables to Each Build Step

Hi there, is it possible to expose all (or a subset) of the pipeline environment variables to all steps in a docker pipeline?

These are the environment variables that I would like my steps to have access to: https://docs.drone.io/pipeline/environment/reference/

Now, thus far, I have been defining the “environment” section of the .drone.yml file like this:

---
kind: pipeline
type: docker
name: Epic pipeline

clone:
  depth: 1

steps:
- name: Build
  image: some/image
  environment:
    DRONE_BRANCH: $DRONE_BRANCH
    DRONE_BUILD_CREATED: $DRONE_BUILD_CREATED
    DRONE_BUILD_STARTED: $DRONE_BUILD_STARTED
    DRONE_BUILD_NUMBER: $DRONE_BUILD_NUMBER
    ...

- name: Build
  image: some/image
  environment:
    DRONE_BRANCH: $DRONE_BRANCH
    DRONE_BUILD_CREATED: $DRONE_BUILD_CREATED
    DRONE_BUILD_STARTED: $DRONE_BUILD_STARTED
    DRONE_BUILD_NUMBER: $DRONE_BUILD_NUMBER
    ...

- name: Notify
  image: some/image
  environment:
    DRONE_BRANCH: $DRONE_BRANCH
    DRONE_BUILD_CREATED: $DRONE_BUILD_CREATED
    DRONE_BUILD_STARTED: $DRONE_BUILD_STARTED
    DRONE_BUILD_NUMBER: $DRONE_BUILD_NUMBER
    ...

trigger:
  event:
  - tag
...

I have .drone.yml files that are similar to this in multiple different projects where most of the steps have need of similar pipeline environment variables.

It would be really nice if I could just tell my Drone runners to expose all of these variables to all of the steps… that way I can clean up my .drone.yml files.

Now, the closest thing that I have found is the DRONE_RUNNER_ENV_FILE where I can set static environment variables… But pipeline variables are clearly dynamically generated with commit details and current build details.

Can you point me in the right direction?

The environment variables at the referenced link are automatically injected into every pipeline step. See the following yaml and build for reference:

Haha, wow… That was an easy fix. Thanks a lot!