Skip to content
返回部署

Bitbucket Pipelines

Bitbucket 原生 CI/CD,bitbucket-pipelines.yml 和 Docker runner。

CI/CD进阶

为什么

Bitbucket Pipelines 内置 Bitbucket,bitbucket-pipelines.yml。基于 Docker 的 runner,自托管 runner 满足自定义需求。

何时使用

Bitbucket 上项目用 Bitbucket Pipelines。非 Bitbucket 避免。

如何做

1. 配置 — bitbucket-pipelines.yml 2. 镜像 — 步骤的 Docker 镜像 3. 流水线 — default、branches、custom 4. 步骤 — script 命令 5. 缓存 — cache: npm 依赖 6. 部署 — staging、production 7. Runner — 自托管自定义

示例

# bitbucket-pipelines.yml image: node:20 pipelines: default: - step: { name: Test, caches: [node], script: [npm ci, npm test] } branches: main: - step: { name: Build, script: [npm ci, npm run build] } - step: name: Deploy deployment: production script: [npx vercel --prod --token $VERCEL_TOKEN]

常见问题

  • ⚠构建分钟用尽 — 免费层有限,升级或自托管 runner
  • ⚠部署不工作 — 仓库设置未配环境
  • ⚠环境间配置漂移 — 使用基础设施即代码(Terraform/Pulumi)保持 dev/staging/prod 一致

最佳实践

  • ✓依赖用 cache — 加速构建,yml 定义
  • ✓环境特定用 deployment — staging/prod 分离配环境变量
  • ✓设置健康检查和优雅关闭 — 处理 SIGTERM 以在退出前排空进行中的请求

常见问题解答