Configuring CI Using Bitbucket Pipelines and Nx

Below is an example of a Bitbucket Pipeline setup for an Nx workspace - building and testing only what is affected.

1image: node:16 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 - npm ci 11 - npx nx format:check 12 - npx nx affected -t lint --base=origin/master --parallel --max-parallel=3 13 - npx nx affected -t test --base=origin/master --parallel --max-parallel=3 --configuration=ci 14 - npx nx affected -t build --base=origin/master --head=HEAD --parallel --max-parallel=3 15 16 branches: 17 main: 18 - step: 19 name: "Build and test affected apps on 'main' branch changes" 20 caches: # optional 21 - node 22 script: 23 - npm ci 24 - npx nx format:check 25 - npx nx affected -t lint --base=origin/master --parallel --max-parallel=3 & npx nx affected -t test --base=HEAD~1 --parallel --max-parallel=3 --configuration=ci & npx nx affected -t build --base=HEAD~1 --parallel --max-parallel=3 26

The pull-requests and main jobs implement the CI workflow.