gitlab-ci
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCI/CD Pipeline Skill
CI/CD 流水线技能
CI/CD pipeline operations for GitLab using the CLI.
glab使用 CLI工具进行GitLab的CI/CD流水线操作。
glabQuick Reference
快速参考
| Operation | Command | Risk |
|---|---|---|
| View status | | - |
| View pipeline | | - |
| List pipelines | | - |
| Run pipeline | | ⚠️ |
| Get pipeline JSON | | - |
| Retry job | | ⚠️ |
| Trace job | | - |
| Download artifacts | | - |
| Lint CI config | | - |
| Delete pipeline | | ⚠️⚠️ |
Risk Legend: - Safe | ⚠️ Caution | ⚠️⚠️ Warning | ⚠️⚠️⚠️ Danger
| 操作 | 命令 | 风险 |
|---|---|---|
| 查看状态 | | - |
| 查看流水线详情 | | - |
| 列出流水线 | | - |
| 运行流水线 | | ⚠️ |
| 获取流水线JSON数据 | | - |
| 重试作业 | | ⚠️ |
| 追踪作业日志 | | - |
| 下载构建产物 | | - |
| 校验CI配置 | | - |
| 删除流水线 | | ⚠️⚠️ |
风险说明: - 安全 | ⚠️ 注意 | ⚠️⚠️ 警告 | ⚠️⚠️⚠️ 危险
When to Use This Skill
何时使用此技能
ALWAYS use when:
- User wants to check pipeline/build status
- User mentions "CI", "CD", "pipeline", "build", "job", "deploy"
- User wants to trigger or retry builds
- User wants to view job logs
NEVER use when:
- User wants to manage CI/CD variables (use gitlab-variable instead)
- User wants to manage schedules (use gitlab-schedule skill)
请务必在以下场景使用:
- 用户想要检查流水线/构建状态
- 用户提到"CI"、"CD"、"pipeline"、"build"、"job"、"deploy"
- 用户想要触发或重试构建
- 用户想要查看作业日志
请勿在以下场景使用:
- 用户想要管理CI/CD变量(请使用gitlab-variable技能)
- 用户想要管理定时任务(请使用gitlab-schedule技能)
Available Commands
可用命令
View Pipeline Status
查看流水线状态
bash
glab ci status [options]Options:
| Flag | Description |
|---|---|
| Check status for specific branch |
| Show status in real-time (updates automatically) |
| Show compact view |
Examples:
bash
undefinedbash
glab ci status [options]选项:
| 标识 | 说明 |
|---|---|
| 查看指定分支的状态 |
| 实时显示状态(自动更新) |
| 显示精简视图 |
示例:
bash
undefinedView current branch pipeline status
查看当前分支的流水线状态
glab ci status
glab ci status
View status for specific branch
查看指定分支的状态
glab ci status --branch=main
glab ci status --branch=main
Watch status live (updates in real-time)
实时监控状态(自动更新)
glab ci status --live
glab ci status --live
Compact view
精简视图
glab ci status --compact
undefinedglab ci status --compact
undefinedInteractive Pipeline View
交互式流水线查看
bash
glab ci view [options]Options:
| Flag | Description |
|---|---|
| View pipeline for specific branch/tag |
| View specific pipeline by ID |
| Open pipeline in browser |
Keyboard shortcuts in view mode:
| Key | Action |
|---|---|
| Close logs or return to pipeline |
| Run, retry, or play a job |
| Navigate |
| Confirm selection |
| Cancel job / Quit view |
Examples:
bash
undefinedbash
glab ci view [options]选项:
| 标识 | 说明 |
|---|---|
| 查看指定分支/标签的流水线 |
| 通过ID查看特定流水线 |
| 在浏览器中打开流水线 |
查看模式下的快捷键:
| 按键 | 操作 |
|---|---|
| 关闭日志或返回流水线视图 |
| 运行、重试或启动作业 |
| 导航 |
| 确认选择 |
| 取消作业 / 退出查看模式 |
示例:
bash
undefinedInteractive view for current branch
交互式查看当前分支的流水线
glab ci view
glab ci view
View specific branch pipeline
查看指定分支的流水线
glab ci view --branch=feature/new
glab ci view --branch=feature/new
View specific pipeline ID
查看特定ID的流水线
glab ci view --pipeline-id=12345
glab ci view --pipeline-id=12345
Open in browser
在浏览器中打开
glab ci view --web
undefinedglab ci view --web
undefinedList Pipelines
列出流水线
bash
glab ci list [options]Options:
| Flag | Description |
|---|---|
| Filter by branch |
| Filter by status: running, pending, success, failed, canceled, skipped |
| List all pipelines (not just default page) |
| Items per page |
Examples:
bash
undefinedbash
glab ci list [options]选项:
| 标识 | 说明 |
|---|---|
| 按分支过滤 |
| 按状态过滤:running、pending、success、failed、canceled、skipped |
| 列出所有流水线(不只是默认页面) |
| 每页显示条目数 |
示例:
bash
undefinedList recent pipelines
列出最近的流水线
glab ci list
glab ci list
List pipelines for branch
列出指定分支的流水线
glab ci list --branch=main
glab ci list --branch=main
List failed pipelines
列出失败的流水线
glab ci list --status=failed
glab ci list --status=failed
List all running pipelines
列出所有运行中的流水线
glab ci list --status=running --all
undefinedglab ci list --status=running --all
undefinedRun/Trigger Pipeline
运行/触发流水线
bash
glab ci run [options]Options:
| Flag | Description |
|---|---|
| Branch or tag to run pipeline on |
| CI variables as key=value pairs (comma-separated) |
Examples:
bash
undefinedbash
glab ci run [options]选项:
| 标识 | 说明 |
|---|---|
| 运行指定分支或标签的流水线 |
| CI变量,格式为key=value,多组用逗号分隔 |
示例:
bash
undefinedRun pipeline for current branch
运行当前分支的流水线
glab ci run
glab ci run
Run pipeline for specific branch
运行指定分支的流水线
glab ci run --branch=main
glab ci run --branch=main
Run with CI variables
携带CI变量运行
glab ci run --variables="DEPLOY_ENV=staging,DEBUG=true"
glab ci run --variables="DEPLOY_ENV=staging,DEBUG=true"
Run for a tag
运行指定标签的流水线
glab ci run --branch=v1.2.3
undefinedglab ci run --branch=v1.2.3
undefinedGet Pipeline JSON
获取流水线JSON数据
bash
glab ci get [options]Get JSON representation of a pipeline.
Options:
| Flag | Description |
|---|---|
| Get pipeline for specific branch |
| Get specific pipeline by ID |
Examples:
bash
undefinedbash
glab ci get [options]获取流水线的JSON格式数据。
选项:
| 标识 | 说明 |
|---|---|
| 获取指定分支的流水线数据 |
| 通过ID获取特定流水线的数据 |
示例:
bash
undefinedGet current branch pipeline
获取当前分支的流水线数据
glab ci get
glab ci get
Get specific pipeline
获取特定ID的流水线数据
glab ci get --pipeline-id=12345
glab ci get --pipeline-id=12345
Pipe to jq for processing
管道输出到jq进行处理
glab ci get | jq '.status'
undefinedglab ci get | jq '.status'
undefinedRetry Job
重试作业
bash
glab ci retry <job-id>Retry a failed CI job.
Examples:
bash
undefinedbash
glab ci retry <job-id>重试失败的CI作业。
示例:
bash
undefinedRetry specific job
重试指定作业
glab ci retry 456789
undefinedglab ci retry 456789
undefinedTrace Job Logs
追踪作业日志
bash
glab ci trace <job-id> [options]View job logs in real-time.
Examples:
bash
undefinedbash
glab ci trace <job-id> [options]实时查看作业日志。
示例:
bash
undefinedTrace job output
追踪作业输出
glab ci trace 456789
undefinedglab ci trace 456789
undefinedDownload Artifacts
下载构建产物
bash
glab ci artifact [options]Download artifacts from the last pipeline.
Options:
| Flag | Description |
|---|---|
| Download from specific branch |
| Download from specific job |
| Download to specific path |
Examples:
bash
undefinedbash
glab ci artifact [options]下载最近一次流水线的构建产物。
选项:
| 标识 | 说明 |
|---|---|
| 从指定分支下载 |
| 从指定作业下载 |
| 下载到指定路径 |
示例:
bash
undefinedDownload all artifacts from last pipeline
下载最近一次流水线的所有构建产物
glab ci artifact
glab ci artifact
Download from specific job
从指定作业下载构建产物
glab ci artifact --job=build
glab ci artifact --job=build
Download to specific directory
下载到指定目录
glab ci artifact --path=./artifacts/
undefinedglab ci artifact --path=./artifacts/
undefinedLint CI Configuration
校验CI配置
bash
glab ci lint [file]Validate .gitlab-ci.yml file.
Examples:
bash
undefinedbash
glab ci lint [file]校验.gitlab-ci.yml文件。
示例:
bash
undefinedLint default .gitlab-ci.yml
校验默认的.gitlab-ci.yml文件
glab ci lint
glab ci lint
Lint specific file
校验指定文件
glab ci lint path/to/.gitlab-ci.yml
undefinedglab ci lint path/to/.gitlab-ci.yml
undefinedDelete Pipeline
删除流水线
bash
glab ci delete <pipeline-id>Warning: This permanently deletes the pipeline and its jobs.
bash
glab ci delete <pipeline-id>警告: 此操作会永久删除流水线及其所有作业。
Common Workflows
常见工作流
Workflow 1: Check and Fix Failed Pipeline
工作流1:检查并修复失败的流水线
bash
undefinedbash
undefined1. Check current status
1. 检查当前状态
glab ci status
glab ci status
2. View failed pipeline interactively
2. 交互式查看失败的流水线
glab ci view
glab ci view
3. Find failed job and view logs (in interactive view)
3. 在交互式视图中找到失败作业并查看日志
Press arrow keys to select job, Enter to view logs
使用方向键选择作业,按Enter查看日志
4. Retry the failed job
4. 重试失败的作业
glab ci retry <job-id>
glab ci retry <job-id>
5. Watch the retry
5. 监控重试过程
glab ci status --live
undefinedglab ci status --live
undefinedWorkflow 2: Trigger Deployment
工作流2:触发部署
bash
undefinedbash
undefined1. Ensure tests pass
1. 确保测试通过
glab ci status --branch=main
glab ci status --branch=main
2. Trigger deployment pipeline with variables
2. 携带变量触发部署流水线
glab ci run --branch=main --variables="DEPLOY_ENV=production"
glab ci run --branch=main --variables="DEPLOY_ENV=production"
3. Monitor deployment
3. 监控部署过程
glab ci status --live
undefinedglab ci status --live
undefinedWorkflow 3: Debug CI Configuration
工作流3:调试CI配置
bash
undefinedbash
undefined1. Lint your CI config
1. 校验CI配置
glab ci lint
glab ci lint
2. If valid, run a test pipeline
2. 如果配置有效,运行测试流水线
glab ci run
glab ci run
3. Watch the results
3. 查看结果
glab ci view
undefinedglab ci view
undefinedWorkflow 4: Download Build Artifacts
工作流4:下载构建产物
bash
undefinedbash
undefined1. Check pipeline succeeded
1. 确认流水线执行成功
glab ci status --branch=release
glab ci status --branch=release
2. Download artifacts from build job
2. 从build作业下载构建产物到指定目录
glab ci artifact --branch=release --job=build --path=./dist/
undefinedglab ci artifact --branch=release --job=build --path=./dist/
undefinedPipeline Status Reference
流水线状态参考
| Status | Meaning |
|---|---|
| Pipeline is currently executing |
| Pipeline is waiting to run |
| All jobs passed |
| One or more jobs failed |
| Pipeline was manually canceled |
| Pipeline was skipped |
| Waiting for manual trigger |
| Scheduled to run later |
| 状态 | 含义 |
|---|---|
| 流水线正在执行 |
| 流水线等待执行 |
| 所有作业执行成功 |
| 一个或多个作业执行失败 |
| 流水线被手动取消 |
| 流水线被跳过 |
| 等待手动触发 |
| 已定时,将在稍后运行 |
Troubleshooting
故障排除
| Issue | Cause | Solution |
|---|---|---|
| Authentication failed | Invalid/expired token | Run |
| Pipeline not found | No pipeline for branch | Check branch name or run |
| Job stuck pending | No runners available | Check runner configuration |
| Lint fails | Invalid YAML syntax | Fix syntax errors in .gitlab-ci.yml |
| Cannot retry | Job not in retryable state | Wait for current run or cancel first |
| 问题 | 原因 | 解决方案 |
|---|---|---|
| 认证失败 | 令牌无效/过期 | 运行 |
| 未找到流水线 | 该分支没有流水线 | 检查分支名称,或运行 |
| 作业一直处于等待状态 | 没有可用的运行器 | 检查运行器配置 |
| 校验失败 | YAML语法错误 | 修复.gitlab-ci.yml中的语法错误 |
| 无法重试作业 | 作业处于不可重试状态 | 等待当前运行完成或先取消作业 |
Related Documentation
相关文档
- Safeguards
- Quick Reference
- 安全防护
- 快速参考