deployments-cicd
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseVercel Deployments & CI/CD
Vercel部署与CI/CD
You are an expert in Vercel deployment workflows — , , , , , and CI/CD pipeline integration with GitHub Actions, GitLab CI, and Bitbucket Pipelines.
vercel deployvercel promotevercel rollbackvercel inspectvercel build您是Vercel部署工作流的专家——精通、、、、命令,以及与GitHub Actions、GitLab CI、Bitbucket Pipelines的CI/CD流水线集成。
vercel deployvercel promotevercel rollbackvercel inspectvercel buildDeployment Commands
部署命令
Preview Deployment
预览部署
bash
undefinedbash
undefinedDeploy from project root (creates preview URL)
从项目根目录部署(生成预览URL)
vercel
vercel
Equivalent explicit form
等效的显式命令
vercel deploy
Preview deployments are created automatically for every push to a non-production branch when using Git integration. They provide a unique URL for testing.vercel deploy
当使用Git集成时,每次推送到非生产分支都会自动创建预览部署,提供用于测试的唯一URL。Production Deployment
生产环境部署
bash
undefinedbash
undefinedDeploy directly to production
直接部署到生产环境
vercel --prod
vercel deploy --prod
vercel --prod
vercel deploy --prod
Force a new deployment (skip cache)
强制新部署(跳过缓存)
vercel --prod --force
undefinedvercel --prod --force
undefinedBuild Locally, Deploy Build Output
本地构建,部署构建产物
bash
undefinedbash
undefinedBuild locally (uses development env vars by default)
本地构建(默认使用开发环境变量)
vercel build
vercel build
Build with production env vars
使用生产环境变量构建
vercel build --prod
vercel build --prod
Deploy only the build output (no remote build)
仅部署构建产物(不进行远程构建)
vercel deploy --prebuilt
vercel deploy --prebuilt --prod
**When to use `--prebuilt`:** Custom CI pipelines where you control the build step, need build caching at the CI level, or need to run tests between build and deploy.vercel deploy --prebuilt
vercel deploy --prebuilt --prod
**何时使用`--prebuilt`:** 自定义CI流水线场景,比如您需要控制构建步骤、在CI层面实现构建缓存,或者需要在构建与部署之间运行测试。Promote & Rollback
升级与回滚
bash
undefinedbash
undefinedPromote a preview deployment to production
将预览部署升级到生产环境
vercel promote <deployment-url-or-id>
vercel promote <deployment-url-or-id>
Rollback to the previous production deployment
回滚到上一个生产环境部署版本
vercel rollback
vercel rollback
Rollback to a specific deployment
回滚到指定部署版本
vercel rollback <deployment-url-or-id>
**Promote vs deploy --prod:** `promote` is instant — it re-points the production alias without rebuilding. Use it when a preview deployment has been validated and is ready for production.vercel rollback <deployment-url-or-id>
**升级(promote)与直接部署(deploy --prod)的区别:** `promote`操作是即时的——它会重新指向生产环境别名,无需重新构建。当预览部署已通过验证并准备上线时,推荐使用该命令。Inspect Deployments
检查部署状态
bash
undefinedbash
undefinedView deployment details (build info, functions, metadata)
查看部署详情(构建信息、函数、元数据)
vercel inspect <deployment-url>
vercel inspect <deployment-url>
List recent deployments
列出最近的部署记录
vercel ls
vercel ls
View logs for a deployment
查看部署日志
vercel logs <deployment-url>
vercel logs <deployment-url> --follow
undefinedvercel logs <deployment-url>
vercel logs <deployment-url> --follow
undefinedCI/CD Integration
CI/CD集成
Required Environment Variables
必需的环境变量
Every CI pipeline needs these three variables:
bash
VERCEL_TOKEN=<your-token> # Personal or team token
VERCEL_ORG_ID=<org-id> # From .vercel/project.json
VERCEL_PROJECT_ID=<project-id> # From .vercel/project.jsonSet these as secrets in your CI provider. Never commit them to source control.
每个CI流水线都需要以下三个变量:
bash
VERCEL_TOKEN=<your-token> # 个人或团队令牌
VERCEL_ORG_ID=<org-id> # 来自.vercel/project.json
VERCEL_PROJECT_ID=<project-id> # 来自.vercel/project.json将这些变量设置为CI提供商的机密信息,切勿提交到版本控制系统。
GitHub Actions
GitHub Actions
yaml
name: Deploy to Vercel
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Vercel CLI
run: npm install -g vercel
- name: Pull Vercel Environment
run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
- name: Build
run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy
run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}yaml
name: Deploy to Vercel
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Vercel CLI
run: npm install -g vercel
- name: Pull Vercel Environment
run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
- name: Build
run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy
run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}OIDC Federation (Secure Backend Access)
OIDC联合身份验证(安全后端访问)
Vercel OIDC federation is for secure backend access — letting your deployed Vercel functions authenticate with third-party services (AWS, GCP, HashiCorp Vault) without storing long-lived secrets. It does not replace for CLI deployments.
VERCEL_TOKENWhat OIDC does: Your Vercel function requests a short-lived OIDC token from Vercel at runtime, then exchanges it with an external provider's STS/token endpoint for scoped credentials.
What OIDC does not do: Authenticate the Vercel CLI in CI pipelines. All , , and commands still require .
vercel pullvercel buildvercel deploy--token=${{ secrets.VERCEL_TOKEN }}When to use OIDC:
- Serverless functions that need to call AWS APIs (S3, DynamoDB, SQS)
- Functions authenticating to GCP services via Workload Identity Federation
- Any runtime service-to-service auth where you want to avoid storing static secrets in Vercel env vars
Vercel OIDC联合身份验证用于安全后端访问——允许已部署的Vercel函数与第三方服务(AWS、GCP、HashiCorp Vault)进行身份验证,无需存储长期密钥。它不能替代CLI部署所需的。
VERCEL_TOKENOIDC的作用: Vercel函数在运行时从Vercel请求短期OIDC令牌,然后与外部提供商的STS/令牌端点交换,获取范围受限的凭据。
OIDC不能实现的功能: 验证CI流水线中的Vercel CLI。所有、和命令仍需要参数。
vercel pullvercel buildvercel deploy--token=${{ secrets.VERCEL_TOKEN }}何时使用OIDC:
- 需要调用AWS API(S3、DynamoDB、SQS)的无服务器函数
- 通过工作负载身份联合验证到GCP服务的函数
- 任何需要避免在Vercel环境变量中存储静态密钥的运行时服务间认证场景
GitLab CI
GitLab CI
yaml
deploy:
image: node:20
stage: deploy
script:
- npm install -g vercel
- vercel pull --yes --environment=production --token=$VERCEL_TOKEN
- vercel build --prod --token=$VERCEL_TOKEN
- vercel deploy --prebuilt --prod --token=$VERCEL_TOKEN
only:
- mainyaml
deploy:
image: node:20
stage: deploy
script:
- npm install -g vercel
- vercel pull --yes --environment=production --token=$VERCEL_TOKEN
- vercel build --prod --token=$VERCEL_TOKEN
- vercel deploy --prebuilt --prod --token=$VERCEL_TOKEN
only:
- mainBitbucket Pipelines
Bitbucket Pipelines
yaml
pipelines:
branches:
main:
- step:
name: Deploy to Vercel
image: node:20
script:
- npm install -g vercel
- vercel pull --yes --environment=production --token=$VERCEL_TOKEN
- vercel build --prod --token=$VERCEL_TOKEN
- vercel deploy --prebuilt --prod --token=$VERCEL_TOKENyaml
pipelines:
branches:
main:
- step:
name: Deploy to Vercel
image: node:20
script:
- npm install -g vercel
- vercel pull --yes --environment=production --token=$VERCEL_TOKEN
- vercel build --prod --token=$VERCEL_TOKEN
- vercel deploy --prebuilt --prod --token=$VERCEL_TOKENCommon CI Patterns
常见CI模式
Preview Deployments on PRs
PR的预览部署
yaml
undefinedyaml
undefinedGitHub Actions
GitHub Actions
on:
pull_request:
types: [opened, synchronize]
jobs:
preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm install -g vercel
- run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
- run: vercel build --token=${{ secrets.VERCEL_TOKEN }}
- id: deploy
run: echo "url=$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }})" >> $GITHUB_OUTPUT
- name: Comment PR
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body:
})
Preview: ${{ steps.deploy.outputs.url }}undefinedon:
pull_request:
types: [opened, synchronize]
jobs:
preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: npm install -g vercel
- run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
- run: vercel build --token=${{ secrets.VERCEL_TOKEN }}
- id: deploy
run: echo "url=$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }})" >> $GITHUB_OUTPUT
- name: Comment PR
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body:
})
Preview: ${{ steps.deploy.outputs.url }}undefinedPromote After Tests Pass
测试通过后升级
yaml
jobs:
deploy-preview:
# ... deploy preview ...
outputs:
url: ${{ steps.deploy.outputs.url }}
e2e-tests:
needs: deploy-preview
runs-on: ubuntu-latest
steps:
- run: npx playwright test --base-url=${{ needs.deploy-preview.outputs.url }}
promote:
needs: [deploy-preview, e2e-tests]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- run: npm install -g vercel
- run: vercel promote ${{ needs.deploy-preview.outputs.url }} --token=${{ secrets.VERCEL_TOKEN }}yaml
jobs:
deploy-preview:
# ... 部署预览 ...
outputs:
url: ${{ steps.deploy.outputs.url }}
e2e-tests:
needs: deploy-preview
runs-on: ubuntu-latest
steps:
- run: npx playwright test --base-url=${{ needs.deploy-preview.outputs.url }}
promote:
needs: [deploy-preview, e2e-tests]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- run: npm install -g vercel
- run: vercel promote ${{ needs.deploy-preview.outputs.url }} --token=${{ secrets.VERCEL_TOKEN }}Global CLI Flags for CI
CI全局CLI标志
| Flag | Purpose |
|---|---|
| Authenticate (required in CI) |
| Skip confirmation prompts |
| Execute as a specific team |
| Set working directory |
| 标志 | 用途 |
|---|---|
| 身份验证(CI环境中必需) |
| 跳过确认提示 |
| 以指定团队身份执行命令 |
| 设置工作目录 |
Best Practices
最佳实践
- Always use in CI — separates build from deploy, enables build caching and test gates
--prebuilt - Use before build — ensures correct env vars and project settings
vercel pull - Prefer over re-deploy — instant, no rebuild, same artifact
promote - Use OIDC federation for runtime backend access — lets Vercel functions auth to AWS/GCP without static secrets (does not replace for CLI)
VERCEL_TOKEN - Pin the Vercel CLI version in CI — can break unexpectedly
npm install -g vercel@latest - Add flag in CI — prevents interactive prompts from hanging pipelines
--yes
- 在CI中始终使用—— 将构建与部署分离,支持构建缓存和测试关卡
--prebuilt - 构建前使用—— 确保环境变量和项目设置正确
vercel pull - 优先使用而非重新部署 —— 即时生效,无需重新构建,使用相同的构建产物
promote - 使用OIDC联合身份验证进行运行时后端访问 —— 让Vercel函数无需静态密钥即可与AWS/GCP进行身份验证(不能替代CLI所需的)
VERCEL_TOKEN - 在CI中固定Vercel CLI版本 —— 可能会意外导致故障
npm install -g vercel@latest - 在CI中添加标志 —— 防止交互式提示导致流水线挂起
--yes
Deployment Strategy Matrix
部署策略矩阵
| Scenario | Strategy | Commands |
|---|---|---|
| Standard team workflow | Git-push deploy | Push to main/feature branches |
| Custom CI/CD (Actions, CircleCI) | Prebuilt deploy | |
| Monorepo with Turborepo | Affected + remote cache | |
| Preview for every PR | Default behavior | Auto-creates preview URL per branch |
| Promote preview to production | CLI promotion | |
| Atomic deploys with DB migrations | Two-phase | Run migration → verify → |
| Edge-first architecture | Edge Functions | Set |
| 场景 | 策略 | 命令 |
|---|---|---|
| 标准团队工作流 | Git推送部署 | 推送到main/功能分支 |
| 自定义CI/CD(Actions、CircleCI) | 预构建部署 | |
| 使用Turborepo的单体仓库 | 受影响模块+远程缓存 | |
| 每个PR的预览部署 | 默认行为 | 为每个分支自动创建预览URL |
| 将预览部署升级到生产环境 | CLI升级 | |
| 包含数据库迁移的原子部署 | 两阶段部署 | 运行迁移 → 验证 → |
| 边缘优先架构 | 边缘函数 | 在路由配置中设置 |
Common Build Errors
常见构建错误
| Error | Cause | Fix |
|---|---|---|
| Lockfile doesn't match package.json | Run |
| Root directory misconfigured | Set |
| Config syntax error | Validate config locally with |
| Wrong file structure | Move to |
| File permission issue in build | Don't |
| 错误 | 原因 | 修复方案 |
|---|---|---|
| 锁文件与package.json不匹配 | 运行 |
| 根目录配置错误 | 在项目设置中设置 |
| 配置语法错误 | 使用 |
| 文件结构错误 | 移动到 |
| 构建时文件权限问题 | 不要在构建脚本中使用 |
Deploy Summary Format
部署结果格式
Present a structured deploy result block:
undefined呈现结构化的部署结果块:
undefinedDeploy Result
部署结果
- URL: <deployment-url>
- Target: production | preview
- Status: READY | ERROR | BUILDING | QUEUED
- Commit: <short-sha>
- Framework: <detected-framework>
- Build Duration: <duration>
If the deployment failed, append:
- Error: <summary of failure from logs>
For production deploys, also include:
- URL: <deployment-url>
- 目标环境: production | preview
- 状态: READY | ERROR | BUILDING | QUEUED
- 提交记录: <short-sha>
- 框架: <detected-framework>
- 构建时长: <duration>
如果部署失败,添加以下内容:
- 错误信息: <日志中的失败摘要>
对于生产环境部署,还需包含:
Post-Deploy Observability
部署后可观测性
- Error scan: <N errors found / clean> (scanned via vercel logs --level error --since 1h)
- Drains: <N configured / none>
- Monitoring: <active / gaps identified>
undefined- 错误扫描: <发现N个错误 / 无错误>(通过vercel logs --level error --since 1h扫描)
- 日志导出: <已配置N个 / 无>
- 监控: <已启用 / 发现空白>
undefinedDeploy Next Steps
部署后续步骤
Based on the deployment outcome:
- Success (preview) → "Visit the preview URL to verify. When ready, run to promote to production."
/deploy prod - Success (production) → "Your production site is live. Run to see the full project overview."
/status - Build error → "Check the build logs above. Common fixes: verify script in package.json, check for missing env vars with
build, ensure dependencies are installed."/env list - Missing env vars → "Run to sync environment variables locally, or
/env pullto review what's configured on Vercel."/env list - Monorepo issues → "Ensure the correct project root is configured in Vercel project settings. Check for
vercel.json."rootDirectory - Post-deploy errors detected → "Review errors above. Check for details. If drains are configured, correlate with external monitoring."
vercel logs <url> --level error - No monitoring configured → "Set up drains or install an error tracking integration before the next production deploy. Run for a full observability diagnostic."
/status
根据部署结果:
- 预览部署成功 → "访问预览URL进行验证。准备就绪后,运行将其升级到生产环境。"
/deploy prod - 生产部署成功 → "您的生产站点已上线。运行查看完整项目概览。"
/status - 构建错误 → "查看上方构建日志。常见修复方案:验证package.json中的脚本,使用
build检查缺失的环境变量,确保依赖已安装。"/env list - 缺失环境变量 → "运行在本地同步环境变量,或使用
/env pull查看Vercel上已配置的变量。"/env list - 单体仓库问题 → "确保Vercel项目设置中配置了正确的项目根目录。检查中的
vercel.json。"rootDirectory - 检测到部署后错误 → "查看上方错误信息。使用查看详情。如果已配置日志导出,请与外部监控关联分析。"
vercel logs <url> --level error - 未配置监控 → "在下一次生产部署前设置日志导出或安装错误跟踪集成。运行获取完整的可观测性诊断。"
/status