Configuring CI Using Bitbucket Pipelines and Nx
Below is an example of an Bitbucket Pipelines, building and testing only what is affected.
bitbucket-pipelines.yml
1image: node:20
2pipelines:
3 pull-requests:
4 '**':
5 - step:
6 name: 'Build and test affected apps on Pull Requests'
7 caches: # optional
8 - node
9 script:
10 - npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" # this line enables distribution
11 - npm ci
12 - npx nx-cloud record -- nx format:check
13 - npx nx affected -t lint test build --base=origin/master --head=HEAD
14
15 branches:
16 main:
17 - step:
18 name: "Build and test affected apps on 'main' branch changes"
19 caches: # optional
20 - node
21 script:
22 - npx nx-cloud start-ci-run --distribute-on="5 linux-medium-js" --stop-agents-after="build" # this line enables distribution
23 - npm ci
24 - npx nx-cloud record -- nx format:check
25 - npx nx affected -t lint test build --base=HEAD~1
26
The pull-requests
and main
jobs implement the CI workflow.