Skip to content
Back to Knowledge Base

Setting Up CI for Nx Cloud

Learn how to set up Nx Cloud for your workspace with your preferred CI platform. Get started connecting to Nx Cloud by running

Terminal window
nx connect

Each platform has specific configurations and optimizations that help you build and test only what is affected, retrieve previous successful builds, and optimize CI performance.

From PNPM Workspaces to Distributed CI

Watch full course

Each example combines a .nx/ci-config.yaml file that configures task distribution across Nx Agents with a provider workflow that starts those agents by running nx-cloud start-nx-agents. See the CI configuration file reference for every key you can set.

Need a starting point? Generate a new workflow file with the following command:

Terminal window
nx g ci-workflow --ci=github

Add a .nx/ci-config.yaml file to configure task distribution:

.nx/ci-config.yaml
dte:
distribute-on: 3 linux-medium-js
lifecycle:
stop-after:
- build

Below is an example of a GitHub Actions setup, building, and testing only what is affected.

.github/workflows/ci.yml
name: CI
on:
push:
branches:
- main
pull_request:
permissions:
actions: read
contents: read
jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
filter: tree:0
fetch-depth: 0
# This enables task distribution via Nx Cloud
# Run this command as early as possible, before dependencies are installed
- run: npx nx-cloud start-nx-agents
# Cache node_modules
- uses: actions/setup-node@v6
with:
node-version: 24
cache: 'npm'
- run: npm ci
- uses: nrwl/nx-set-shas@v5
# Prepend any command with "nx record --" to record its logs to Nx Cloud
# - run: npx nx record -- echo Hello World
- run: npx nx affected -t lint test build
# Nx Cloud recommends fixes for failures to help you get CI green faster. Learn more: https://nx.dev/ci/features/self-healing-ci
- run: npx nx fix-ci
if: always()

Get the commit of the last successful build

Section titled “Get the commit of the last successful build”

The GitHub can track the last successful run on the main branch and use this as a reference point for the BASE. The nrwl/nx-set-shas provides a convenient implementation of this functionality, which you can drop into your existing CI workflow.

To understand why knowing the last successful build is important for the affected command, check out the in-depth explanation in Actions's docs.

All CI platforms support task distribution via Nx Cloud. To enable it:

  1. Connect your workspace by running nx connect
  2. Commit a .nx/ci-config.yaml file with your distribution and stop conditions
  3. Run npx nx-cloud start-nx-agents at the start of your main job

Learn more in the CI configuration file reference.

Nx Cloud can recommend fixes for failures to help you get CI green faster. The nx fix-ci command is included in all platform configurations and runs automatically after failures.

Learn more about Self-Healing CI features.

You can record any command's logs to Nx Cloud by prepending it with nx record --. This helps with debugging and monitoring your CI pipeline.

Example:

Terminal window
npx nx record -- echo Hello World

Last updated: