diff --git a/docs/shared/reference/environment-variables.md b/docs/shared/reference/environment-variables.md index 554bacd084..8567f47f02 100644 --- a/docs/shared/reference/environment-variables.md +++ b/docs/shared/reference/environment-variables.md @@ -13,6 +13,7 @@ The following environment variables are ones that you can set to change the beha | NX_PROFILE | string | Prepend `NX_PROFILE=profile.json` before running targets with Nx to generate a file that be [loaded in Chrome dev tools](/recipes/other/performance-profiling) to visualize the performance of Nx across multiple processes. | | NX_PROJECT_GRAPH_CACHE_DIRECTORY | string | The project graph cache is stored in `node_modules/.cache/nx` by default. Set this variable to use a different directory. | | NX_PROJECT_GRAPH_MAX_WORKERS | number | The number of workers to use when calculating the project graph. | +| NX_RUNNER | string | The name of task runner from the config to use. Can be overridden on the command line with `--runner`. | | NX_SKIP_NX_CACHE | boolean | Rerun the tasks even when the results are available in the cache | | NX_TASKS_RUNNER_DYNAMIC_OUTPUT | boolean | If set to `false`, will use non-dynamic terminal output strategy (what you see in CI), even when you terminal can support the dynamic version | | NX_VERBOSE_LOGGING | boolean | If set to `true`, will print debug information useful for troubleshooting | diff --git a/packages/nx/src/utils/command-line-utils.spec.ts b/packages/nx/src/utils/command-line-utils.spec.ts index 78794ca4c0..41f0f77103 100644 --- a/packages/nx/src/utils/command-line-utils.spec.ts +++ b/packages/nx/src/utils/command-line-utils.spec.ts @@ -240,6 +240,39 @@ describe('splitArgs', () => { process.env.NX_HEAD = originalNxHead; }); + it('should set runner based on environment variables, if it is not provided directly on the command', () => { + const originalRunner = process.env.NX_RUNNER; + process.env.NX_RUNNER = 'some-env-runner-name'; + + expect( + splitArgsIntoNxArgsAndOverrides( + { + __overrides_unparsed__: ['--notNxArg', 'true', '--override'], + $0: '', + }, + 'run-one', + {} as any, + {} as any + ).nxArgs.runner + ).toEqual('some-env-runner-name'); + + expect( + splitArgsIntoNxArgsAndOverrides( + { + __overrides_unparsed__: ['--notNxArg', 'true', '--override'], + $0: '', + runner: 'directlyOnCommand', // higher priority than $NX_RUNNER + }, + 'run-one', + {} as any, + {} as any + ).nxArgs.runner + ).toEqual('directlyOnCommand'); + + // Reset process data + process.env.NX_RUNNER = originalRunner; + }); + describe('--parallel', () => { it('should be a number', () => { const parallel = splitArgsIntoNxArgsAndOverrides( diff --git a/packages/nx/src/utils/command-line-utils.ts b/packages/nx/src/utils/command-line-utils.ts index 43cade1a78..3dbc7deee8 100644 --- a/packages/nx/src/utils/command-line-utils.ts +++ b/packages/nx/src/utils/command-line-utils.ts @@ -176,6 +176,17 @@ export function splitArgsIntoNxArgsAndOverrides( nxArgs.skipNxCache = process.env.NX_SKIP_NX_CACHE === 'true'; } + if (!nxArgs.runner && process.env.NX_RUNNER) { + nxArgs.runner = process.env.NX_RUNNER; + if (options.printWarnings) { + output.note({ + title: `No explicit --runner argument provided, but found environment variable NX_RUNNER so using its value: ${output.bold( + `${nxArgs.runner}` + )}`, + }); + } + } + if (args['parallel'] === 'false' || args['parallel'] === false) { nxArgs['parallel'] = 1; } else if (