feat(core): add NX_BAIL environment variable#34711
Conversation
✅ Deploy Preview for nx-docs canceled.
|
✅ Deploy Preview for nx-dev canceled.
|
|
View your CI Pipeline Execution ↗ for commit eb5e527
☁️ Nx Cloud last updated this comment at |
8a6fa71 to
f6245af
Compare
There was a problem hiding this comment.
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
|
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. |
Current Behavior
The
--nxBail/--nx-bailflag can only be set via the CLI: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-bailflag can now also be activated via the NX_BAIL environment variable:This mirrors the pattern used by other Nx environment variables (e.g.
NX_DEFAULT_OUTPUT_STYLEfor--outputStyle)Related Issue(s)
#26899