연속 통합
pnpm은 다양한 ci 시스템들과 함께 사용하기 쉽습니다.
pnpm 설치하기#
On CI systems that run each job in a container image, use the official pnpm
image ghcr.io/pnpm/pnpm as the job image.
pnpm is already on PATH, so the job needs no install step, and
pnpm runtime set node lts -g installs Node.js. The
Bitbucket Pipelines and GitLab CI examples
below use it. If your Dockerfile builds on another image, such as node:24,
copy pnpm from the official image.
Elsewhere, outside of GitHub Actions, which has its own action,
install pnpm with the standalone script. If get.pnpm.io fails, the second
command downloads the same script from the latest
installer release:
{ curl -fsSL https://get.pnpm.io/ -o /tmp/pnpm-install.sh \
|| curl -fsSL https://github.com/pnpm/get.pnpm.io/releases/latest/download/install.sh -o /tmp/pnpm-install.sh; } \
&& sh /tmp/pnpm-install.sh
The script is saved to a file before it runs, and it runs only if one of the downloads succeeded, so a failed download never runs a partial script.
CI에서 이 방식이 편리한 이유는 두 가지입니다:
- Node.js가 필요하지 않습니다. pnpm은 독립 실행형 실행 파일이며, 이후
pnpm runtime set node lts -g로 런타임을 설치할 수 있으므로 작업을 시작할 때 Node.js 이미지가 필요하지 않습니다. - It follows the project's version. The bootstrap installs the newest stable
pnpm, then, if your
package.jsonhas apackageManagerordevEngines.packageManagerfield, pnpm switches to that version on first use, so the pipeline does not pin a version in two places.
이 스크립트는 PNPM_HOME에 설치하고 셸 프로필에 내용을 추가하지만, CI 작업은 셸 프로필을 다시 불러오지 않습니다. Declare PNPM_HOME and put $PNPM_HOME/bin on PATH
yourself, using whatever mechanism the platform provides. The examples below
show it for each one.
참고
Do not use Corepack. It runs pnpm through a Node.js shim on every call.
참고
Most of the provided configuration files cache the store. 하지만 이는 필수가 아니며, 스토어를 캐시한다고 해서 설치가 더 빨라진다는 보장은 없습니다. 따라서 작업에서 pnpm 스토어를 캐시하지 않아도 괜찮습니다.
메타데이터 캐시도 캐시하세요
pnpm cache path prints the directory pnpm
uses for its metadata cache, so a job can cache it without mirroring pnpm's own
path resolution. That directory also holds the lockfile verification log, which
lets a job skip re-checking an unchanged lockfile against the configured
supply-chain policies, the dominant cost of an
install in CI once the store is warm.
important
pnpm의 스토어와 캐시 디렉터리는 신뢰할 수 있는 작업만 쓸 수 있는 위치에만 캐시하세요. 신뢰할 수 있는 작업이 나중에 복원하는 스토어나 메타데이터 캐시에 신뢰할 수 없는 CI 작업이 쓰지 못하도록 하세요. 이 디렉터리들은 신뢰할 수 있는 캐시입니다. 자세한 내용은 storeDir 및 cacheDir 설정을 참조하세요.
CI에서의 lockfile 동작
pnpm은 CI에서 실행 중임을 감지하면 자동으로 frozen-lockfile 모드로 전환합니다. Pass --no-frozen-lockfile to opt out, and set the ci setting to force or disable CI detection. pnpm ci runs pnpm clean and then a frozen install. pnpm also fails on incompatible lockfiles in CI. If the lockfile was written by a newer pnpm major version, the install will error out instead of silently rewriting it. lockfile을 생성할 때 사용한 버전과 일치하도록 CI의 pnpm 버전을 업그레이드하세요.
AppVeyor#
AppVeyor에서는 appveyor.yml에 다음을 추가하여 pnpm으로 종속성을 설치할 수 있습니다:
environment:
PNPM_HOME: C:\pnpm
install:
- ps: $env:PATH = "$env:PNPM_HOME;$env:PNPM_HOME\bin;$env:PATH"
- ps: Invoke-WebRequest https://get.pnpm.io/install.ps1 -UseBasicParsing | Invoke-Expression
- ps: pnpm install
pnpm은 자체 런타임을 제공하므로 더 이상 Install-Product node가 필요하지 않습니다. 빌드 스크립트에서 node를 직접 호출하는 경우 pnpm runtime set node lts -g를 추가하세요.
Azure Pipelines#
On Azure Pipelines, you can use pnpm for installing and caching your dependencies by adding this to your azure-pipelines.yml. The example below avoids a top-level variables: block, so it can also be copied into a steps template:
steps:
- task: Cache@2
inputs:
key: 'pnpm | "$(Agent.OS)" | pnpm-lock.yaml'
path: $(Pipeline.Workspace)/.pnpm-store
displayName: Cache pnpm
- bash: |
{ curl -fsSL https://get.pnpm.io/ -o /tmp/pnpm-install.sh \
|| curl -fsSL https://github.com/pnpm/get.pnpm.io/releases/latest/download/install.sh -o /tmp/pnpm-install.sh; } \
&& sh /tmp/pnpm-install.sh
echo "##vso[task.prependpath]$PNPM_HOME/bin"
"$PNPM_HOME/bin/pnpm" config set store-dir "$PNPM_STORE_PATH"
displayName: "Setup pnpm"
env:
PNPM_HOME: $(Pipeline.Workspace)/.pnpm
PNPM_STORE_PATH: $(Pipeline.Workspace)/.pnpm-store
- bash: |
pnpm install
pnpm run build
displayName: "pnpm install and build"
env:
PNPM_HOME: $(Pipeline.Workspace)/.pnpm
Use a Linux or macOS agent for this example. Azure Pipelines expands
$(Pipeline.Workspace) in task inputs and environment values before each step.
The setup script reads its variables using Bash syntax. task.prependpath puts
pnpm on PATH for subsequent steps.
Bitbucket Pipelines#
pnpm을 통해 dependencies를 설치하고 캐시할 수 있습니다.
definitions:
caches:
pnpm: $BITBUCKET_CLONE_DIR/.pnpm-store
pipelines:
pull-requests:
"**":
- step:
name: Build and test
image: ghcr.io/pnpm/pnpm:12
script:
- pnpm config set store-dir "$BITBUCKET_CLONE_DIR/.pnpm-store"
- pnpm runtime set node lts -g
- pnpm install
- pnpm run build # Replace with your build/test…etc. commands
caches:
- pnpm
The example starts from the official pnpm image, lets pnpm install Node.js, and
points store-dir at the directory the cache saves.
CircleCI#
CircleCI에서는 .circleci/config.yml에 다음을 추가하여 pnpm으로 종속성을 설치하고 캐싱할 수 있습니다:
version: 2.1
jobs:
build: # this can be any name you choose
docker:
- image: node:24
environment:
PNPM_HOME: /root/.local/share/pnpm
steps:
- checkout
- restore_cache:
name: Restore pnpm Package Cache
keys:
- pnpm-packages-{{ checksum "pnpm-lock.yaml" }}
- run:
name: Install pnpm package manager
command: |
{ curl -fsSL https://get.pnpm.io/ -o /tmp/pnpm-install.sh \
|| curl -fsSL https://github.com/pnpm/get.pnpm.io/releases/latest/download/install.sh -o /tmp/pnpm-install.sh; } \
&& sh /tmp/pnpm-install.sh
echo 'export PATH="$PNPM_HOME/bin:$PATH"' >> "$BASH_ENV"
"$PNPM_HOME/bin/pnpm" config set store-dir .pnpm-store
- run:
name: Install Dependencies
command: |
pnpm install
- save_cache:
name: Save pnpm Package Cache
key: pnpm-packages-{{ checksum "pnpm-lock.yaml" }}
paths:
- .pnpm-store
CircleCI는 모든 단계 전에 $BASH_ENV를 불러오며, 이를 통해 pnpm이 이후 단계에서도 사용 가능해집니다.
GitHub Actions#
GitHub Actions에서는 다음과 같이 pnpm으로 종속성을 설치하고 캐싱할 수 있습니다(.github/workflows/NAME.yml에 작성):
name: pnpm Example Workflow
on:
push:
jobs:
build:
runs-on: ubuntu-24.04
strategy:
matrix:
node-version: [24]
steps:
- uses: actions/checkout@v6
- name: Install pnpm and Node.js
uses: pnpm/setup@fa36a5ef7dcdefc3a7cb25655c122e00cf6e636e # v3.1.2
with:
runtime: node@${{ matrix.node-version }}
cache: true
pnpm/setup은 pnpm을 설치한 다음 이를 사용하여 요청된 런타임을 설치하므로, 별도의 actions/setup-node 단계가 필요하지 않습니다. 또한 pnpm install도 대신 실행하며, cache: true는 실행 간에 pnpm 스토어를 캐시합니다. 설치를 직접 실행하려면 install: false로 설정하세요.
사용할 pnpm 버전은 package.json의 packageManager 또는 devEngines.packageManager 필드에서 가져오므로, 버전을 변경해도 워크플로를 업데이트할 필요가 없습니다. package.json에 둘 다 선언되어 있지 않다면 version 입력을 추가하세요.
GitLab CI#
GitLab에서는 다음과 같이 pnpm으로 종속성을 설치하고 캐싱할 수 있습니다(.gitlab-ci.yml에 작성):
stages:
- build
build:
stage: build
image: ghcr.io/pnpm/pnpm:12
before_script:
- pnpm config set store-dir .pnpm-store
- pnpm runtime set node 24 -g
script:
- pnpm install # install dependencies
cache:
key:
files:
- pnpm-lock.yaml
paths:
- .pnpm-store
Jenkins#
You can use pnpm for installing your dependencies:
pipeline {
agent {
docker {
image 'node:lts-bookworm-slim'
}
}
environment {
PNPM_HOME = "${WORKSPACE}/.pnpm"
PATH = "${PNPM_HOME}/bin:${PATH}"
}
stages {
stage('Build') {
steps {
sh '''
{ curl -fsSL https://get.pnpm.io/ -o /tmp/pnpm-install.sh \\
|| curl -fsSL https://github.com/pnpm/get.pnpm.io/releases/latest/download/install.sh -o /tmp/pnpm-install.sh; } \\
&& sh /tmp/pnpm-install.sh
'''
sh 'pnpm install'
}
}
}
}
각 sh 단계는 자체 셸에서 실행되므로, PATH는 단계 내에서 export하는 대신 파이프라인의 environment 블록에서 설정합니다.
Semaphore#
Semaphore에서는 .semaphore/semaphore.yml 파일에 다음을 추가하여 pnpm으로 종속성을 설치하고 캐싱할 수 있습니다:
version: v1.0
name: Semaphore CI pnpm example
agent:
machine:
type: e1-standard-2
os_image: ubuntu2404
blocks:
- name: Install dependencies
task:
env_vars:
- name: PNPM_HOME
value: /home/semaphore/.local/share/pnpm
jobs:
- name: pnpm install
commands:
- export PATH="$PNPM_HOME/bin:$PATH"
- curl -fsSL https://get.pnpm.io/ -o /tmp/pnpm-install.sh || curl -fsSL https://github.com/pnpm/get.pnpm.io/releases/latest/download/install.sh -o /tmp/pnpm-install.sh
- sh /tmp/pnpm-install.sh
- checkout
- cache restore node-$(checksum pnpm-lock.yaml)
- pnpm install
- cache store node-$(checksum pnpm-lock.yaml) $(pnpm store path)
Travis#
Travis CI에서는 .travis.yml 파일에 다음을 추가하여 pnpm으로 종속성을 설치할 수 있습니다:
cache:
npm: false
directories:
- "~/.pnpm-store"
env:
global:
- PNPM_HOME="$HOME/.local/share/pnpm"
- PATH="$PNPM_HOME/bin:$PATH"
before_install:
- curl -fsSL https://get.pnpm.io/ -o /tmp/pnpm-install.sh || curl -fsSL https://github.com/pnpm/get.pnpm.io/releases/latest/download/install.sh -o /tmp/pnpm-install.sh
- sh /tmp/pnpm-install.sh
- pnpm config set store-dir ~/.pnpm-store
install:
- pnpm install