Skip to content

The Nx Cloud command line interface provides various commands to connect and interact with Nx Cloud, manage distributed task execution, and handle authentication. Below is a complete reference for all available commands and their options.

Provision a local personal access token to access Nx Cloud features. This will open your browser to the Nx Cloud application and after signing in will generate a personal access token and save it in a configuration file locally called nxcloud.ini.

This command is the same as running nx login.

Usage:

Terminal window
npx nx-cloud login [nxCloudUrl]
OptionTypeDescriptionDefault
nxCloudUrlstringThe URL of the Nx Cloud instance to connect tohttps://cloud.nx.app

We look for this file at the following locations:

  • $XDG_CONFIG_HOME/nxcloud/nxcloud.ini
  • $HOME/config/nxcloud/nxcloud.ini
  • $HOME/.nxcloud.ini

If we don't find an existing config file, we create one at $HOME/config/nxcloud/nxcloud.ini

The format of this file is as follows:

[https://cloud\.nx\.app]
personalAccessToken=SOME_ACCESS_TOKEN

If you have access to multiple instances of the Nx Cloud application (e.g. self-hosted Enterprise and our managed instance), each instance will be saved to this file under its URL.

Revoke a personal access token from your local environment. This will remove the personal access token from the locally initialized configuration file and also invalidate the token from the Nx Cloud application. You will be prompted to remove a single token or all tokens from your local environment.

Usage:

Terminal window
npx nx-cloud logout

To provision more than one personal access token for multiple contexts (e.g. home and work machines) you can use the personal access tokens page under your Nx Cloud profile. To save a personal access token to your local nxcloud.ini file without needing to edit the file yourself call nx-cloud configure.

Usage:

Terminal window
npx nx-cloud configure
OptionTypeDescriptionDefault
--personalAccessTokenstringThe personal access token to configure
--nx-cloud-urlstringThe URL of the Nx Cloud instancehttps://cloud.nx.app
Terminal window
npx nx-cloud configure --personalAccessToken=SOME_ACCESS_TOKEN

To configure multiple tokens for different instances of the Nx Cloud app:

Terminal window
npx nx-cloud configure --personalAccessToken=SOME_ACCESS_TOKEN --nx-cloud-url=https://nx-cloud.my-domain.app

When logging into Nx Cloud with a Personal Access Token, your nx.json file needs to include the nxCloudId property, which acts as a unique identifier for your workspace. If you have been using the previous nxCloudAccessToken to connect, simply run npx nx-cloud convert-to-nx-cloud-id to automatically update your configuration to use nxCloudId.

If you are connecting to Nx Cloud with a workspace that is version 19.6 or lower, this command will also install the latest version of the Nx Cloud npm package and add it into your package.json. Only Nx versions 19.7 and higher natively support the nxCloudId property in the nx.json file; for versions 19.6 and lower, the Nx Cloud npm package will be needed to use that property.

Usage:

Terminal window
npx nx-cloud convert-to-nx-cloud-id

At the beginning of your main job, invoke npx nx-cloud start-ci-run. This tells Nx Cloud that the following series of command correspond to the same CI run.

Usage:

Terminal window
npx nx-cloud start-ci-run

:::warning[Do not run start-ci-run locally] npx nx-cloud start-ci-run generates a temporary marker file that can cause a local Nx repo to behave as if it is a part of a CI run. This can cause strange behavior like Nx commands timing out or throwing unexpected errors. To discourage this from happening, this command will run a check to see if it is running in a CI environment. You can bypass this check with npx nx-cloud start-ci-run --force.

If you accidentally run this command locally, remove all generated marker files with npx nx-cloud cleanup. :::

OptionTypeDescriptionDefault
--distribute-onstringConfigure the number of agents and launch templates for distributed execution
--require-explicit-completionbooleanDisable automatic completion monitoring and require explicit nx-cloud complete-ci-runfalse
--stop-agents-afterstringComma-separated list of targets after which agents should terminate
--stop-agents-on-failurebooleanTerminate all agents when a command failstrue
--use-dte-by-defaultbooleanConfigure Nx to distribute all commands by defaulttrue
--with-env-varsstringComma-separated list of environment variables to pass to Nx Agents
--forcebooleanBypass CI environment check

By default, npx nx-cloud start-ci-run is intended for use with Nx Agents and expects --distribute-on to be configured. It will output a warning if this flag is not set. If you are running a distributed execution with a legacy setup without Nx Agents, you can pass --distribute-on=manual to disable this warning.

This command tells Nx Cloud how many agents to use (and what launch templates to use) to distribute tasks. E.g., npx nx-cloud start-ci-run --distribute-on="8 linux-medium-js" will distribute CI using 8 agents that are initialized using the linux-medium-js launch template.

You can also define the configuration in a file and reference it as follows: npx nx-cloud start-ci-run --distribute-on=".nx/workflows/dynamic-changesets.yaml".

.nx/workflows/dynamic-changesets.yaml
distribute-on:
small-changeset: 3 linux-medium-js
medium-changeset: 6 linux-medium-js
large-changeset: 10 linux-medium-js

You can tell Nx Cloud to terminate agents after it sees a certain target or group of targets: npx nx-cloud start-ci-run --stop-agents-after=build,test,e2e.

:::tip[Be as specific] For the best results, always tell Nx Cloud about all targets that should be expected during your pipeline. This will prevent your CI Pipeline Execution from ending prematurely, cutting off any unfinished work. :::

Whether you are running commands serially or in parallel (through use of the & operand or discrete jobs), you should include one or more targets from each command.

- run: npx nx-cloud start-ci-run --stop-agents-after=build
- run: nx affected -t build
- run: nx affected -t lint
- run: nx affected -t test

Nx Cloud will only look for the presence of a build target before determining your pipeline can be shut down. Since both lint and test will only run after build is complete, your pipeline would end before all intended work is executed.

- run: npx nx-cloud start-ci-run --stop-agents-after=lint,test,build
- run: nx affected -t lint
- run: nx affected -t test
- run: nx affected -t build

In advanced pipeline setups, it is possible that you want to run multiple commands with the same target, but with distinct configurations. An example of this may be doing static translations for different locales during your builds.

- run: npx nx-cloud start-ci-run --stop-agents-after=build
- run: nx affected -t build --configuration=locale-en
- run: nx affected -t build --configuration=locale-es

In this case, the build target will be executed twice, once with the locale-en configuration and once with the locale-es configuration. However, Nx Cloud is only looking for the build target to assess whether the CI Pipeline Execution can be marked complete.

To address this, you can pass an optional configuration to make your targets more specific.

- run: npx nx-cloud start-ci-run --stop-agents-after=build:locale-en,build:locale-es
- run: nx affected -t build --configuration=locale-en
- run: nx affected -t build --configuration=locale-es

By default, invoking npx nx-cloud start-ci-run will take all environment variables prefixed with NX_ and send them over to Nx Agents. This means that your access token, verbose logging configuration and other Nx-related environment variables will be the same on your main CI jobs and the Nx Agent machines.

If you want to pass other environment variables from the main job to Nx Agents, you can do it as follows: --with-env-vars="VAR1,VAR2". This will set VAR1 and VAR2 on Nx Agents to the same values set on the main job before any steps run.

Note: none of the values passed to Nx Agents are stored by Nx Cloud.

Invoking npx nx-cloud start-ci-run will tell Nx to distribute by default. You can enable/disable distribution for individual commands as follows:

  • nx affected -t build --agents (explicitly enable distribution)
  • nx affected -t build --no-agents (explicitly disable distribution)

Same as npx nx-cloud complete-ci-run.

This command tells Nx Cloud to terminate all agents associated with this CI pipeline execution. Invoking this command is not needed anymore. New versions of Nx Cloud can track when the main job terminates and terminate associated agents automatically.

Usage:

Terminal window
npx nx-cloud stop-all-agents

Explicitly complete a CI run when using --require-explicit-completion with start-ci-run.

Usage:

Terminal window
npx nx-cloud complete-ci-run

Remove temporary marker files created by start-ci-run if accidentally run locally.

Usage:

Terminal window
npx nx-cloud cleanup

You can get help for any command by adding the --help flag:

Terminal window
npx nx-cloud <command> --help