Skip to content

Allow configuration via environment variables - #2860

Open
youdie006 wants to merge 2 commits into
cucumber:mainfrom
youdie006:feat/env-var-config
Open

Allow configuration via environment variables#2860
youdie006 wants to merge 2 commits into
cucumber:mainfrom
youdie006:feat/env-var-config

Conversation

@youdie006

@youdie006 youdie006 commented Jun 22, 2026

Copy link
Copy Markdown

🤔 What's changed?

Each configuration option can now be set via an environment variable (#2347). An option's key is converted to CUCUMBER_OPTION_<SCREAMING_SNAKE> — e.g. retryTagFilterCUCUMBER_OPTION_RETRY_TAG_FILTER — following @davidjgoss's design in the issue.

  • Precedence: CLI > environment > config file > default (env slots into mergeConfigurations between the config file and CLI), preserving the existing merge-vs-overwrite semantics (e.g. CUCUMBER_OPTION_TAGS and --tags combine into (@a) and (@b)).
  • Values are parsed as JSON where possible (booleans / numbers / arrays) and validated against the config schema; unknown CUCUMBER_OPTION_* vars are ignored. Profile-level options are out of scope, per the issue.
  • New internal fromEnv module; the public API surface is unchanged (verified by api-extractor).

⚡️ What's your motivation?

Fixes #2347 — lets every configuration option be provided via the environment (useful in CI), which previously wasn't possible for most options.

🏷️ What kind of change is this?

  • ⚡ New feature (non-breaking change which adds new behaviour)

♻️ Anything particular you want feedback on?

The precedence placement (env between config file and CLI) and the CUCUMBER_OPTION_TAGS merge semantics — happy to adjust if you'd prefer different behaviour. Quick manual check: CUCUMBER_OPTION_DRY_RUN=true skips scenarios; CUCUMBER_OPTION_TAGS='@wip' with --tags 'not @wip' resolves to (@wip) and (not @wip).

📋 Checklist:

  • I agree to respect and uphold the Cucumber Community Code of Conduct
  • I've changed the behaviour of the code
    • I have added/updated tests to cover my changes.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • Users should know about my change
    • I have added an entry to the "Unreleased" section of the CHANGELOG, linking to this pull request.

@davidjgoss davidjgoss left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for raising this @youdie006. It looks good at a glance, but please can you follow the standard pull request template including the CoC acknowledgement:
https://raw.githubusercontent.com/cucumber/.github/refs/heads/main/.github/PULL_REQUEST_TEMPLATE.md

youdie006 and others added 2 commits July 3, 2026 14:35
Each configuration option can now be set via a CUCUMBER_OPTION_<SCREAMING_SNAKE>
environment variable (e.g. retryTagFilter -> CUCUMBER_OPTION_RETRY_TAG_FILTER),
following the design in cucumber#2347. Env values sit between the config file and the
CLI in precedence (CLI > env > config file > default) and keep the existing
merge semantics (tag expressions combine). Values are parsed as JSON where
possible and validated against the config schema; unknown CUCUMBER_OPTION_* vars
are ignored. Adds docs, a changelog entry, and tests.
@youdie006
youdie006 force-pushed the feat/env-var-config branch from 96f1d5d to c5e2259 Compare July 3, 2026 05:36
@youdie006

Copy link
Copy Markdown
Author

Thanks @davidjgoss! I've updated the description to the standard template with the Code of Conduct acknowledgement, and pointed the CHANGELOG entry at this PR. Ready for another look when you have a moment.

@davidjgoss davidjgoss left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again. A couple of suggestions to improve.

Comment thread docs/configuration.md
CUCUMBER_OPTION_PARALLEL=2 CUCUMBER_OPTION_RETRY_TAG_FILTER='@flaky' cucumber-js
```

Values are parsed as JSON where possible, so booleans, numbers, arrays and objects can be expressed, while anything that isn't valid JSON (like a tag expression) is kept as a plain string:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an implementation detail and we could do without having it in the user-facing documentation.

@davidjgoss davidjgoss Jul 8, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this now, I think my steer to have CUCUMBER_OPTION be the prefix we look for was a mistake and it's led us to a more complex implementation than is needed.

First, there are no collisions with other env vars, and given we also support CUCUMBER_PUBLISH_URL and CUCUMBER_PUBLISH_TOKEN, having the extra prefix causes fragmentation from a user perspective. So I think just e.g. CUCUMBER_RETRY_TAG_FILTER is fine.

Second, we already have the list of option names to check (from the default flag config object), so we can have fewer loops and less code by simply iterating over those keys, and for each one forming the env var key and checking env for it - no need to iterate over the whole env object.

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.

allow configuration via environment variables

2 participants