# Configuring CI Using Bitbucket Pipelines and Nx Nx is a smart, fast and extensible build system, and it works really well with monorepos. Monorepos provide a lot of advantages: - Everything at that current commit works together. Changes can be verified across all affected parts of the organization. - Easy to split code into composable modules - Easier dependency management - One toolchain setup - Code editors and IDEs are "workspace" aware - Consistent developer experience - And more ... But they come with their own technical challenges. The more code you add into your repository, the slower the CI gets. ## Setting Bitbucket Pipelines Below is an example of a Bitbucket Pipeline setup for an Nx workspace only building and testing what is affected. ```yaml image: node:16 pipelines: pull-requests: '**': - step: name: "Build and test affected apps on Pull Requests" caches: # optional - node script: - npm ci - npx nx workspace-lint - npx nx format:check - npx nx affected --target=lint --base=origin/master --parallel --max-parallel=3 - npx nx affected --target=test --base=origin/master --parallel --max-parallel=3 --ci --code-coverage - npx nx affected --target=build --base=origin/master --head=HEAD --parallel --max-parallel=3 branches: main: - step: name: "Build and test affected apps on 'main' branch changes" caches: # optional - node script: - npm ci - npx nx workspace-lint - npx nx format:check - npx nx affected --target=lint --base=origin/master --parallel --max-parallel=3 - npx nx affected --target=test --base=HEAD~1 --parallel --max-parallel=3 --ci --code-coverage - npx nx affected --target=build --base=HEAD~1 --parallel --max-parallel=3 ``` The `pull-requests` and `main` jobs implement the CI workflow.