关于 gitlab-ci
gitlab-ci 是通过 `glab` CLI 操作 GitLab CI/CD 流水线的技能,涵盖流水线监控、作业排查、配置检查和制品下载。
主要功能
- 01查看并筛选流水线状态
- 02运行流水线或重试作业
- 03查看作业日志
- 04下载流水线制品
- 05检查 CI 配置
适用场景
- 01检查分支的构建状态
- 02通过日志排查失败作业
- 03触发并监控部署流水线
- 04下载构建制品
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ grandcamel/ gitlab-assistant-skills --skill gitlab-ci安装后在 Claude Code 中输入/gitlab-ci确认已加载。
详细介绍
CI/CD 流水线技能
使用 glab CLI 执行 GitLab CI/CD 流水线操作。
快速参考
| 操作 | 命令 | 风险 |
|---|---|---|
| 查看状态 | glab ci status | - |
| 查看流水线 | glab ci view | - |
| 列出流水线 | glab ci list | - |
| 运行流水线 | glab ci run | ⚠️ |
| 获取流水线 JSON | glab ci get | - |
| 重试作业 | glab ci retry <job-id> | ⚠️ |
| 查看作业日志 | glab ci trace <job-id> | - |
| 下载构件 | glab ci artifact | - |
| 检查 CI 配置 | glab ci lint | - |
| 删除流水线 | glab ci delete <id> | ⚠️⚠️ |
风险图例:- 安全 | ⚠️ 注意 | ⚠️⚠️ 警告 | ⚠️⚠️⚠️ 危险
何时使用此技能
始终在以下情况下使用:
- 用户想检查流水线/构建状态
- 用户提到“CI”、“CD”、“流水线”、“构建”、“作业”、“部署”
- 用户想触发或重试构建
- 用户想查看作业日志
以下情况下绝不要使用:
- 用户想管理 CI/CD 变量(改用 gitlab-variable)
- 用户想管理计划任务(改用 gitlab-schedule 技能)
可用命令
查看流水线状态
glab ci status [options]
选项:
| 标志 | 说明 |
|---|---|
-b, --branch=<branch> | 检查指定分支的状态 |
-l, --live | 实时显示状态(自动更新) |
-c, --compact | 显示紧凑视图 |
示例:
# View current branch pipeline status
glab ci status
# View status for specific branch
glab ci status --branch=main
# Watch status live (updates in real-time)
glab ci status --live
# Compact view
glab ci status --compact
交互式流水线视图
glab ci view [options]
选项:
| 标志 | 说明 |
|---|---|
-b, --branch=<branch> | 查看指定分支/标签的流水线 |
-p, --pipeline-id=<id> | 按 ID 查看指定流水线 |
-w, --web | 在浏览器中打开流水线 |
视图模式下的键盘快捷键:
| 按键 | 操作 |
|---|---|
Esc 或 q | 关闭日志或返回流水线 |
Ctrl+R 或 Ctrl+P | 运行、重试或播放作业 |
Tab / 方向键 | 导航 |
Enter | 确认选择 |
Ctrl+D | 取消作业/退出视图 |
示例:
# Interactive view for current branch
glab ci view
# View specific branch pipeline
glab ci view --branch=feature/new
# View specific pipeline ID
glab ci view --pipeline-id=12345
# Open in browser
glab ci view --web
列出流水线
glab ci list [options]
选项:
| 标志 | 说明 |
|---|---|
-b, --branch=<branch> | 按分支筛选 |
--status=<status> | 按状态筛选:running、pending、success、failed、canceled、skipped |
--all | 列出所有流水线(而非仅默认页面中的流水线) |
-P, --per-page=<n> | 每页项目数 |
示例:
# List recent pipelines
glab ci list
# List pipelines for branch
glab ci list --branch=main
# List failed pipelines
glab ci list --status=failed
# List all running pipelines
glab ci list --status=running --all
运行/触发流水线
glab ci run [options]
选项:
| 标志 | 说明 |
|---|---|
-b, --branch=<ref> | 运行流水线的分支或标签 |
--variables=<vars> | 以 key=value 对形式指定 CI 变量(逗号分隔) |
示例:
# Run pipeline for current branch
glab ci run
# Run pipeline for specific branch
glab ci run --branch=main
# Run with CI variables
glab ci run --variables="DEPLOY_ENV=staging,DEBUG=true"
# Run for a tag
glab ci run --branch=v1.2.3
获取流水线 JSON
glab ci get [options]
获取流水线的 JSON 表示。
选项:
| 标志 | 说明 |
|---|---|
-b, --branch=<branch> | 获取指定分支的流水线 |
-p, --pipeline-id=<id> | 按 ID 获取指定流水线 |
示例:
# Get current branch pipeline
glab ci get
# Get specific pipeline
glab ci get --pipeline-id=12345
# Pipe to jq for processing
glab ci get | jq '.status'
重试作业
glab ci retry <job-id>
重试失败的 CI 作业。
示例:
# Retry specific job
glab ci retry 456789
查看作业日志
glab ci trace <job-id> [options]
实时查看作业日志。
示例:
# Trace job output
glab ci trace 456789
下载构件
glab ci artifact [options]
下载最近一次流水线的构件。
选项:
| 标志 | 说明 |
|---|---|
-b, --branch=<branch> | 下载指定分支的构件 |
-j, --job=<job-name> | 下载指定作业的构件 |
-p, --path=<path> | 下载到指定路径 |
示例:
# Download all artifacts from last pipeline
glab ci artifact
# Download from specific job
glab ci artifact --job=build
# Download to specific directory
glab ci artifact --path=./artifacts/
检查 CI 配置
glab ci lint [file]
验证 .gitlab-ci.yml 文件。
示例:
# Lint default .gitlab-ci.yml
glab ci lint
# Lint specific file
glab ci lint path/to/.gitlab-ci.yml
删除流水线
glab ci delete <pipeline-id>
警告: 此操作会永久删除流水线及其作业。
常见工作流
工作流 1:检查并修复失败的流水线
# 1. Check current status
glab ci status
# 2. View failed pipeline interactively
glab ci view
# 3. Find failed job and view logs (in interactive view)
# Press arrow keys to select job, Enter to view logs
# 4. Retry the failed job
glab ci retry <job-id>
# 5. Watch the retry
glab ci status --live
工作流 2:触发部署
# 1. Ensure tests pass
glab ci status --branch=main
# 2. Trigger deployment pipeline with variables
glab ci run --branch=main --variables="DEPLOY_ENV=production"
# 3. Monitor deployment
glab ci status --live
工作流 3:调试 CI 配置
# 1. Lint your CI config
glab ci lint
# 2. If valid, run a test pipeline
glab ci run
# 3. Watch the results
glab ci view
工作流 4:下载构建构件
# 1. Check pipeline succeeded
glab ci status --branch=release
# 2. Download artifacts from build job
glab ci artifact --branch=release --job=build --path=./dist/
流水线状态参考
| 状态 | 含义 |
|---|---|
running | 流水线当前正在执行 |
pending | 流水线正在等待运行 |
success | 所有作业均已通过 |
failed | 一个或多个作业失败 |
canceled | 流水线已被手动取消 |
skipped | 流水线已跳过 |
manual | 等待手动触发 |
scheduled | 计划稍后运行 |
故障排查
| 问题 | 原因 | 解决方案 |
|---|---|---|
| 身份验证失败 | 令牌无效或已过期 | 运行 glab auth login |
| 找不到流水线 | 分支没有对应的流水线 | 检查分支名称或运行 glab ci run |
| 作业一直处于等待状态 | 没有可用的运行器 | 检查运行器配置 |
| Lint 失败 | YAML 语法无效 | 修复 .gitlab-ci.yml 中的语法错误 |
| 无法重试 | 作业当前状态不支持重试 | 等待当前运行完成或先取消 |
相关文档
评论
支持 Markdown