跳到主内容
版本:9.x

持续集成

pnpm 可以很容易地用于各种持续集成系统。

注意

在所有本文提供的配置文件中,存储都被缓存了。 但是,这不是必需的,并且不能保证缓存存储将使安装速度变得更快。 因此,您不必在作业中缓存 pnpm 存储。

Travis

Travis CI 上,请将此添加到你的 .travis.yml 文件中以使用 pnpm 来安装你的依赖项:

.travis.yml
cache:
npm: false
directories:
- "~/.pnpm-store"
before_install:
- corepack enable
- corepack prepare pnpm@latest-9 --activate
- pnpm config set store-dir ~/.pnpm-store
install:
- pnpm install

Semaphore

在 [Semapore] 上,请将此内容添加到 .semaphore/semaphore.yml 文件中以使用 pnpm 来安装和缓存你的依赖:

.semaphore/semaphore.yml
version: v1.0
name: Semaphore CI pnpm example
agent:
machine:
type: e1-standard-2
os_image: ubuntu1804
blocks:
- name: 安装依赖
task:
jobs:
- name: pnpm 安装
commands:
- corepack enable
- corepack prepare pnpm@latest-9 --activate
- checkout
- cache restore node-$(checksum pnpm-lock.yaml)
- pnpm install
- cache store node-$(checksum pnpm-lock.yaml) $(pnpm store path)

AppVeyor

AppVeyor 上,在你的 appveyor.yml 中添加这些来使用 pnpm 安装你的依赖项:

appveyor.yml
install:
- ps: Install-Product node $env:nodejs_version
- corepack enable
- corepack prepare pnpm@latest-9 --activate
- pnpm install

GitHub Actions

在 GitHub Actions 上,你可以像这样使用 pnpm 安装和缓存你的依赖项(属于 ·.github/workflows/NAME.yml·):

.github/workflows/NAME.yml
name: pnpm 示例工作流
on:
push:

jobs:
build:
runs-on: ubuntu-22.04
strategy:
matrix:
node-version: [20]
steps:
- uses: actions/checkout@v4
- name: 安装 pnpm
uses: pnpm/action-setup@v4
with:
version: 9
- name: 使用 Nnode.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'
- name: 安装依赖
run: pnpm install

GitLab CI

在 Gitlab 上,你可以像这样使用 pnpm 来安装和缓存你的依赖项(在 .gitlab-ci.yml 中):

.gitlab-ci.yml
stages:
- build

build:
stage: build
image: node:18.17.1
before_script:
- corepack enable
- corepack prepare pnpm@latest-9 --activate
- pnpm config set store-dir .pnpm-store
script:
- pnpm install # install dependencies
cache:
key:
files:
- pnpm-lock.yaml
paths:
- .pnpm-store

Bitbucket Pipelines

你可以使用 pnpm 来安装和缓存你的依赖项:

.bitbucket-pipelines.yml
definitions:
caches:
pnpm: $BITBUCKET_CLONE_DIR/.pnpm-store

pipelines:
pull-requests:
"**":
- step:
name: Build and test
image: node:18.17.1
script:
- corepack enable
- corepack prepare pnpm@latest-9 --activate
- pnpm install
- pnpm run build # Replace with your build/test…etc. commands
caches:
- pnpm

Azure Pipelines

在 Azure pipeline 中,你可以将以下内容添加到 Azure-Pipelines.yml 中,使用 pnpm 安装和缓存依赖项`:

azure-pipelines.yml
variables:
pnpm_config_cache: $(Pipeline.Workspace)/.pnpm-store

steps:
- task: Cache@2
inputs:
key: 'pnpm | "$(Agent.OS)" | pnpm-lock.yaml'
path: $(pnpm_config_cache)
displayName: Cache pnpm

- script: |
corepack enable
corepack prepare pnpm@latest-9 --activate
pnpm config set store-dir $(pnpm_config_cache)
displayName: "Setup pnpm"

- script: |
pnpm install
pnpm run build
displayName: "pnpm install and build"

CircleCI

在 CircleCI 中,你可以将以下内容添加到 .circleci/config.yml 中,使用 pnpm 安装和缓存依赖项`:

.circleci/config.yml
version: 2.1

jobs:
build: # this can be any name you choose
docker:
- image: node:18
resource_class: large
parallelism: 10

steps:
- checkout
- restore_cache:
name: Restore pnpm Package Cache
keys:
- pnpm-packages-{{ checksum "pnpm-lock.yaml" }}
- run:
name: Install pnpm package manager
command: |
corepack enable
corepack prepare pnpm@latest-9 --activate
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

Jenkins

你可以使用 pnpm 来安装和缓存你的依赖项:

pipeline {
agent {
docker {
image 'node:lts-bullseye-slim'
args '-p 3000:3000'
}
}
stages {
stage('Build') {
steps {
sh 'corepack enable'
sh 'corepack prepare pnpm@latest-9 --activate'
sh 'pnpm install'
}
}
}
}