Dynamically Allocate Agents
The standard way to set up Nx Agents is to use this flag:
1--distribute-on="8 linux-medium-js"
2
...which always runs tasks on the same amount of machines, you can also have Nx Cloud scale the number of agents based on the size of your PR. Specify the number and type of agents to use for small, medium and large changesets by creating a yaml file like this:
1distribute-on:
2 small-changeset: 3 linux-medium-js
3 medium-changeset: 6 linux-medium-js
4 large-changeset: 10 linux-medium-js
5
To determine the size of the PR, Nx Cloud calculates the relationship between the number of affected projects and the total number of projects in the workspace. It then assigns it to one of the three categories: small, medium, or large.
You can then reference it in your CI pipeline configuration:
1...
2jobs:
3 - job: main
4 displayName: Main Job
5 ...
6 steps:
7 - checkout
8 - run: npx nx-cloud start-ci-run --distribute-on=".nx/workflows/dynamic-changesets.yaml" --stop-agents-after="e2e-ci"
9 - ...
10
Now PRs that affect a small percentage of the repo will run on 3 agent, mid-size PRs will use 6 agents and large PRs will use 10 agents. This feature helps save costs on the smaller PRs while maintaining the high performance necessary for large PRs.