Skip to content

State that step-level env variables override pipeline-level values#1129

Open
mokagio wants to merge 1 commit intobuildkite:mainfrom
mokagio:patch-1
Open

State that step-level env variables override pipeline-level values#1129
mokagio wants to merge 1 commit intobuildkite:mainfrom
mokagio:patch-1

Conversation

@mokagio
Copy link

@mokagio mokagio commented Aug 26, 2021

This PR updates the note regarding the environment variables overriding behavior in the documentation to reflect the behavior experienced in production.

Details

This pipeline:

env:
  GLOBAL: global value we don't try to override
  GLOBAL_OVERRIDE: if you read this, then the global value takes precendence

steps:
  - label: "Test for env variables resolution"
    command: |
      echo "GLOBAL = $$GLOBAL"
      echo "GLOBAL_OVERRIDE = $$GLOBAL_OVERRIDE"
      echo "LOCAL = $$LOCAL"
    env:
      LOCAL: local value
      GLOBAL_OVERRIDE: if you read this, then the global value was overridden by the local one

Results in this output:

GLOBAL = global value we don't try to override
GLOBAL_OVERRIDE = if you read this, then the global value was overridden by the local one
LOCAL = local value

That is, the value for GLOBAL_OVERRIDE set in the step env node takes precedence over the value set in the env node in the pipeline root.

You can verify the behavior in action here.

Rationale

I opened a PR directly, rather than going through an issue first, because the behavior I see in production is what I would expect from a hierarchical configuration system and I'm guessing the docs are either out of date or wrong.

It's possible my expectation is incorrect, in which case this PR should be closed and a fix should be issued in the way the agent (?) resolves the variables hierarchy.

Next Steps

I've checked the "Allow edits by maintainers" option, so you can take this over and reword my phrasing if needed.


Thanks! I love Buildkite ❤️

This pipeline:

```yml
env:
  GLOBAL: global value we don't try to override
  GLOBAL_OVERRIDE: if you read this, then the global value takes precendence

steps:
  - label: "Test for env variables resolution"
    command: |
      echo "GLOBAL = $$GLOBAL"
      echo "GLOBAL_OVERRIDE = $$GLOBAL_OVERRIDE"
      echo "LOCAL = $$LOCAL"
    env:
      LOCAL: local value
      GLOBAL_OVERRIDE: if you read this, then the global value was overridden by the local one
```

Results in this output:

```
GLOBAL = global value we don't try to override
GLOBAL_OVERRIDE = if you read this, then the global value was overridden by the local one
LOCAL = local value
```

That is, the value for `GLOBAL_OVERRIDE` set in the step `env` node takes precedence over the value set in the `env` node in the pipeline root.

This commit updates the note regarding the environment variables overriding behavior in the documentation to reflect that.
@plaindocs
Copy link
Contributor

Hey @mokagio I love the level of detail you've gone to on this PR. 🌟

I did a little digging and it turns out that it isn't quite as straightforward as this though, apparently the behavior changes depending on whether you're using a YAML pipeline or the older visual step editor.

I'll work on making that clear in the docs.

@plaindocs plaindocs temporarily deployed to docs-review-pr-1129 February 16, 2022 13:12 Inactive
pull bot pushed a commit to Reality2byte/docs-1 that referenced this pull request Feb 23, 2026
Move agent lifecycle content to a new top-level page for the Agent docs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants