Skip to content

feat(core): add NX_BAIL environment variable#34711

Merged
AgentEnder merged 8 commits intonrwl:masterfrom
jase88:feat/nx-bail-env-var
Apr 15, 2026
Merged

feat(core): add NX_BAIL environment variable#34711
AgentEnder merged 8 commits intonrwl:masterfrom
jase88:feat/nx-bail-env-var

Conversation

@jase88
Copy link
Copy Markdown
Contributor

@jase88 jase88 commented Mar 4, 2026

Current Behavior

The --nxBail / --nx-bail flag can only be set via the CLI:

nx run-many -t build --nxBail

There is no way to enable bail-on-first-failure through an environment variable. Users who want this behavior permanently (e.g., in CI) must always pass the flag explicitly in every command invocation.

Expected Behavior

The --nxBail / --nx-bail flag can now also be activated via the NX_BAIL environment variable:

NX_BAIL=true nx run-many -t build

This mirrors the pattern used by other Nx environment variables (e.g. NX_DEFAULT_OUTPUT_STYLE for --outputStyle)

Related Issue(s)

#26899

@jase88 jase88 requested review from a team as code owners March 4, 2026 21:32
@jase88 jase88 requested a review from FrozenPandaz March 4, 2026 21:32
@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 4, 2026

Deploy Preview for nx-docs canceled.

Name Link
🔨 Latest commit eb5e527
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/69d6b0eedf739a0007c8ca65

@netlify
Copy link
Copy Markdown

netlify Bot commented Mar 4, 2026

Deploy Preview for nx-dev canceled.

Name Link
🔨 Latest commit 45910f9
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/69d6b0a6df739a0007c8c186

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented Mar 5, 2026

View your CI Pipeline Execution ↗ for commit eb5e527

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 46m 51s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 7s View ↗
nx-cloud record -- pnpm nx conformance:check ✅ Succeeded 7s View ↗
nx build workspace-plugin ✅ Succeeded <1s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-15 21:41:33 UTC

@AgentEnder AgentEnder force-pushed the feat/nx-bail-env-var branch from 8a6fa71 to f6245af Compare March 6, 2026 03:47
@jase88 jase88 requested a review from a team as a code owner March 28, 2026 06:50
nx-cloud[bot]

This comment was marked as outdated.

Comment thread packages/nx/src/command-line/yargs-utils/shared-options.ts
Copy link
Copy Markdown
Contributor

@nx-cloud nx-cloud Bot left a comment

Choose a reason for hiding this comment

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

Important

At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.

Nx Cloud is proposing a fix for your failed CI:

We removed the default: false from the nxBail option so that yargs leaves the value as undefined when no CLI flag is passed, allowing the middleware's === undefined check to correctly detect the absence of an explicit argument. Without this change, yargs would always assign false before the middleware ran, making the NX_BAIL environment variable completely ineffective. This fix ensures NX_BAIL=true activates bail behavior while explicit CLI flags continue to take precedence.

Warning

We could not verify this fix.

Suggested Fix changes
diff --git a/packages/nx/src/command-line/yargs-utils/shared-options.ts b/packages/nx/src/command-line/yargs-utils/shared-options.ts
index d6bb979600..f72e25b92b 100644
--- a/packages/nx/src/command-line/yargs-utils/shared-options.ts
+++ b/packages/nx/src/command-line/yargs-utils/shared-options.ts
@@ -113,11 +113,10 @@ export function withRunOptions<T>(yargs: Argv<T>): Argv<T & RunOptions> {
     .option('nxBail', {
       describe: 'Stop command execution after the first failed task.',
       type: 'boolean',
-      default: false,
     })
     .middleware((args) => {
-      if (args.nxBail === undefined && process.env.NX_BAIL === 'true') {
-        args.nxBail = true;
+      if (args.nxBail === undefined) {
+        args.nxBail = process.env.NX_BAIL === 'true';
       }
     })
     .option('nxIgnoreCycles', {

🔔 Heads up, your workspace has pending recommendations ↗ to auto-apply fixes for similar failures.

Because this branch comes from a fork, it is not possible for us to apply fixes directly, but you can apply the changes locally using the available options below.

Apply changes locally with:

npx nx-cloud apply-locally Q6L5-9cjg

Apply fix locally with your editor ↗   View interactive diff ↗



🎓 Learn more about Self-Healing CI on nx.dev

@AgentEnder AgentEnder merged commit b6e0775 into nrwl:master Apr 15, 2026
18 checks passed
@jase88 jase88 deleted the feat/nx-bail-env-var branch April 16, 2026 05:21
@github-actions
Copy link
Copy Markdown
Contributor

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants