@aws-blocks/pipeline

中文文档
0.2.4发布于 2026/11/02Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 22.5万

CDK Pipelines-based CI/CD construct for AWS Blocks applications

原始使用文档
文档目录5 节
  1. Usage
  2. Per-stage post-deploy steps ( postStage )
  3. Controlling the synth runtime
  4. Pin a specific Node.js version
  5. Opt out of the Node.js 22 default

@aws-blocks/pipeline

CDK Pipelines-based CI/CD construct for AWS Blocks applications.

Creates one self-mutating CodePipeline V2 per branch. Each pipeline:

  • Pulls source from GitHub via AWS CodeConnections (OAuth, no tokens)
  • Runs a synth step (install + cdk synth)
  • Self-mutates if the pipeline definition changes
  • Deploys to ordered stages with optional manual approval and bake time

Usage

import { Pipeline } from '@aws-blocks/pipeline';

new Pipeline(stack, 'Pipeline', {
  source: {
    repo: 'my-org/my-app',
    connectionArn: 'arn:aws:codeconnections:us-east-1:123456789012:connection/abc',
  },
  branches: [
    {
      branch: 'main',
      stages: [
        { name: 'beta' },
        { name: 'prod', requireApproval: true, config: { domain: 'myapp.com' } },
      ],
    },
  ],
  stageFactory: (scope, stageConfig) => {
    new MyAppStack(scope, 'App', { env: stageConfig.env });
  },
});

For async stage factories (for example, BlocksStack.create()), use the static Pipeline.create() method instead of new Pipeline().

Per-stage post-deploy steps (postStage)

The optional postStage prop runs a second per-stage phase after a stage deploys — for example a step that consumes the stage's deploy outputs. It is invoked once per deploy stage and returns steps that are attached as that stage's post-deploy actions:

import { Duration } from 'aws-cdk-lib';
import { CodeBuildStep } from 'aws-cdk-lib/pipelines';

new Pipeline(stack, 'Pipeline', {
  source: { repo: 'my-org/my-app', connectionArn: '...' },
  branches: [{ branch: 'main', stages: [{ name: 'beta' }, { name: 'prod', bakeTime: Duration.minutes(10) }] }],
  stageFactory: (scope, stageConfig) => new MyAppStack(scope, 'App', { env: stageConfig.env }),
  postStage: ({ stage, stageConfig, source }) => [
    new CodeBuildStep(`Smoke-${stageConfig.name}`, {
      input: source, // the resolved pipeline source — see below
      env: { STAGE: stageConfig.name },
      commands: ['npm ci', 'npm run smoke'],
    }),
  ],
});

The hook receives a PostStageContext:

  • stage — the CDK Stage the returned steps attach to.
  • stageConfig — the full stage config, including env (the stage's target account/region); read it to make a post step target the same account/region.
  • source — the resolved pipeline source file set for this stage's branch. Use it as a step's input so the step runs against the already-checked-out source. This is exposed precisely so a caller never has to walk the construct tree and string-match internal stage IDs to rediscover the source (which silently breaks on any internal rename).

Ordering with bakeTime. When a stage has both postStage steps and a bakeTime, the bake step is made to depend on the post-stage steps, so baking begins only after they complete rather than racing them in parallel. Returning undefined (or []) adds nothing and leaves synthesis identical to a pipeline with no hook.

Controlling the synth runtime

The synth step's CodeBuild runtime can be customized via synth.partialBuildSpec. It accepts three forms:

  • Omitted (undefined): the synth step declares Node.js 22 as the runtime. This is the default and recommended path.
  • null: explicit opt-out. No partialBuildSpec is injected, so the synthesized buildspec contains no runtime-versions block. Use this to bring your own runtime (for example via synth.installCommands) or to rely on the build image's built-in runtime.
  • A BuildSpec: used as-is, replacing the Node.js 22 default.

Pin a specific Node.js version

import { BuildSpec } from 'aws-cdk-lib/aws-codebuild';

new Pipeline(stack, 'Pipeline', {
  // ...
  synth: {
    partialBuildSpec: BuildSpec.fromObject({
      phases: { install: { 'runtime-versions': { nodejs: 20 } } },
    }),
  },
});

Opt out of the Node.js 22 default

Pass null to suppress the injected runtime entirely and manage it yourself:

new Pipeline(stack, 'Pipeline', {
  // ...
  synth: {
    partialBuildSpec: null,
    installCommands: ['n 20'], // or rely on the build image's default runtime
  },
});

版本与发布记录

@aws-blocks/pipeline 共发布 9 个版本,首次发布于 2026/06/20;过去 12 个月发布了 9 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.2.4latest2026/11/025 天前
0.0.0-canary.esql-canary.c93c81b.1791235863canary-esql-canary2026/10/061 个月前
0.2.32026/10/051 个月前
0.0.0-canary.esql-canary.f7f39ac.17909891272026/10/031 个月前
0.0.0-canary.ci-publish-canary-npm.f53dfdc.1790988617canary-ci-publish-canary-npm2026/10/031 个月前
0.2.22026/09/181 个月前

关于 @aws-blocks/pipeline 的常见问题

@aws-blocks/pipeline 是什么?

CDK Pipelines-based CI/CD construct for AWS Blocks applications

如何安装 @aws-blocks/pipeline?

在项目目录运行 npm install @aws-blocks/pipeline,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:constructs(^10.6.0)、aws-cdk-lib(^2.257.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@aws-blocks/pipeline 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@aws-blocks/pipeline 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@aws-blocks/pipeline 可以商用吗?

@aws-blocks/pipeline 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@aws-blocks/pipeline 的下载量有多少?

根据 npm 官方下载统计,@aws-blocks/pipeline 在 2026/10/07 – 2026/11/05 这 30 天内被下载 225,259 次,日均约 7,509 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aws-blocks/pipeline 还在维护吗?

最新版本 0.2.4 发布于 2026/11/02(5 天前);至今共发布 9 个版本,其中过去 12 个月发布了 9 个;首次发布于 2026/06/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。