Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): include target and configuration being run in env variables #15668

Merged
merged 1 commit into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/shared/reference/environment-variables.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Environment Variables

The following environment variables are ones that you can set to change the behavior of Nx in different environments.

| Property | Type | Description |
| -------------------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| NX_BASE | string | The default base branch to use when calculating the affected projects. Can be overridden on the command line with `--base`. |
Expand All @@ -16,3 +18,13 @@
| NX_VERBOSE_LOGGING | boolean | If set to `true`, will print debug information useful for troubleshooting |
| NX_DRY_RUN | boolean | If set to `true`, will perform a dry run of the generator. No files will be created and no packages will be installed. |
| NX_INTERACTIVE | boolean | If set to `true`, will allow Nx to prompt you in the terminal to answer some further questions when running generators. |

Nx will set the following environment variables so they can be accessible within the process even outside of executors and generators

| Property | Type | Description |
| ---------------------------- | ------- | --------------------------------------------------------------------------------------------------------------------- |
| NX_TASK_TARGET_PROJECT | string | Set to the project name of the task being run. Use this to tell which project is being run. |
| NX_TASK_TARGET_TARGET | string | Set to the target name of the task being run. Use this to tell which target of the project is being run. |
| NX_TASK_TARGET_CONFIGURATION | string | Set to the configuration name of the task being run. Use this to tell which configuration of the target is being run. |
| NX_DRY_RUN | boolean | Set to `true` during dry runs of generators. Use this to avoid side effects during generators. |
| NX_INTERACTIVE | boolean | Set to `false` when running generators with `--interactive=false`. Use this to prevent prompting during generators |
2 changes: 2 additions & 0 deletions packages/nx/src/tasks-runner/forked-process-task-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ export class ForkedProcessTaskRunner {
) {
const env: NodeJS.ProcessEnv = {
NX_TASK_TARGET_PROJECT: task.target.project,
NX_TASK_TARGET_TARGET: task.target.target,
NX_TASK_TARGET_CONFIGURATION: task.target.configuration,
Comment on lines +354 to +355

This comment was marked as resolved.

NX_TASK_HASH: task.hash,
// used when Nx is invoked via Lerna
LERNA_PACKAGE_NAME: task.target.project,
Expand Down