Continuous Integration

pnpm can easily be used in various continuous integration systems.

Travis

On Travis CI, you can use pnpm for installing your dependencies by adding this to your .travis.yml file:

.travis.yml

  1. cache:
  2. npm: false
  3. directories:
  4. - "~/.pnpm-store"
  5. before_install:
  6. - corepack enable
  7. - corepack prepare pnpm@latest-7 --activate
  8. - pnpm config set store-dir ~/.pnpm-store
  9. install:
  10. - pnpm install

Semaphore

On Semaphore, you can use pnpm for installing and caching your dependencies by adding this to your .semaphore/semaphore.yml file:

.semaphore/semaphore.yml

  1. version: v1.0
  2. name: Semaphore CI pnpm example
  3. agent:
  4. machine:
  5. type: e1-standard-2
  6. os_image: ubuntu1804
  7. blocks:
  8. - name: Install dependencies
  9. task:
  10. jobs:
  11. - name: pnpm install
  12. commands:
  13. - corepack enable
  14. - corepack prepare pnpm@latest-7 --activate
  15. - checkout
  16. - cache restore node-$(checksum pnpm-lock.yaml)
  17. - pnpm install
  18. - cache store node-$(checksum pnpm-lock.yaml) $(pnpm store path)

AppVeyor

On AppVeyor, you can use pnpm for installing your dependencies by adding this to your appveyor.yml:

appveyor.yml

  1. install:
  2. - ps: Install-Product node $env:nodejs_version
  3. - corepack enable
  4. - corepack prepare pnpm@latest-7 --activate
  5. - pnpm install

GitHub Actions

On GitHub Actions, you can use pnpm for installing and caching your dependencies like so (belongs in .github/workflows/NAME.yml):

.github/workflows/NAME.yml

  1. name: pnpm Example Workflow
  2. on:
  3. push:
  4. jobs:
  5. build:
  6. runs-on: ubuntu-20.04
  7. strategy:
  8. matrix:
  9. node-version: [15]
  10. steps:
  11. - uses: actions/checkout@v3
  12. - uses: pnpm/action-setup@v2
  13. with:
  14. version: 7
  15. - name: Use Node.js ${{ matrix.node-version }}
  16. uses: actions/setup-node@v3
  17. with:
  18. node-version: ${{ matrix.node-version }}
  19. cache: 'pnpm'
  20. - name: Install dependencies
  21. run: pnpm install

Continuous Integration - 图1note

Caching packages dependencies with actions/setup-node@v2 requires you to install pnpm with version 6.10+.

GitLab CI

On GitLab, you can use pnpm for installing and caching your dependencies like so (belongs in .gitlab-ci.yml):

.gitlab-ci.yml

  1. stages:
  2. - build
  3. build:
  4. stage: build
  5. image: node:14.16.0-buster
  6. before_script:
  7. - corepack enable
  8. - corepack prepare pnpm@latest-7 --activate
  9. - pnpm config set store-dir .pnpm-store
  10. script:
  11. - pnpm install # install dependencies
  12. cache:
  13. key:
  14. files:
  15. - pnpm-lock.yaml
  16. paths:
  17. - .pnpm-store

Bitbucket Pipelines

You can use pnpm for installing and caching your dependencies:

.bitbucket-pipelines.yml

  1. definitions:
  2. caches:
  3. pnpm: $BITBUCKET_CLONE_DIR/.pnpm-store
  4. pipelines:
  5. pull-requests:
  6. "**":
  7. - step:
  8. name: Build and test
  9. image: node:14.16.0
  10. script:
  11. - corepack enable
  12. - corepack prepare pnpm@latest-7 --activate
  13. - pnpm install
  14. - pnpm run build # Replace with your build/test…etc. commands
  15. caches:
  16. - pnpm

Azure Pipelines

On Azure Pipelines, you can use pnpm for installing and caching your dependencies by adding this to your azure-pipelines.yml:

azure-pipelines.yml

  1. variables:
  2. pnpm_config_cache: $(Pipeline.Workspace)/.pnpm-store
  3. steps:
  4. - task: Cache@2
  5. inputs:
  6. key: 'pnpm | "$(Agent.OS)" | pnpm-lock.yaml'
  7. path: $(pnpm_config_cache)
  8. displayName: Cache pnpm
  9. - script: |
  10. corepack enable
  11. corepack prepare pnpm@latest-7 --activate
  12. pnpm config set store-dir $(pnpm_config_cache)
  13. displayName: "Setup pnpm"
  14. - script: |
  15. pnpm install
  16. pnpm run build
  17. displayName: "pnpm install and build"

CircleCI

On CircleCI, you can use pnpm for installing and caching your dependencies by adding this to your .circleci/config.yml:

.circleci/config.yml

  1. version: 2.1
  2. jobs:
  3. build: # this can be any name you choose
  4. docker:
  5. - image: node:18
  6. resource_class: large
  7. parallelism: 10
  8. steps:
  9. - checkout
  10. - restore_cache:
  11. name: Restore pnpm Package Cache
  12. keys:
  13. - pnpm-packages-{{ checksum "pnpm-lock.yaml" }}
  14. - run:
  15. name: Install pnpm package manager
  16. command: |
  17. corepack enable
  18. corepack prepare pnpm@latest-7 --activate
  19. - run:
  20. name: Install Dependencies
  21. command: |
  22. pnpm install
  23. - save_cache:
  24. name: Save pnpm Package Cache
  25. key: pnpm-packages-{{ checksum "pnpm-lock.yaml" }}
  26. paths:
  27. - node_modules

Jenkins

You can use pnpm for installing and caching your dependencies:

  1. pipeline {
  2. agent {
  3. docker {
  4. image 'node:lts-bullseye-slim'
  5. args '-p 3000:3000'
  6. }
  7. }
  8. stages {
  9. stage('Build') {
  10. steps {
  11. sh 'corepack enable'
  12. sh 'corepack prepare pnpm@latest-7 --activate'
  13. sh 'pnpm install'
  14. }
  15. }
  16. }
  17. }