gitlab-ci

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

CI/CD Pipeline Skill

CI/CD 流水线技能

CI/CD pipeline operations for GitLab using the
glab
CLI.
使用
glab
CLI工具进行GitLab的CI/CD流水线操作。

Quick Reference

快速参考

OperationCommandRisk
View status
glab ci status
-
View pipeline
glab ci view
-
List pipelines
glab ci list
-
Run pipeline
glab ci run
⚠️
Get pipeline JSON
glab ci get
-
Retry job
glab ci retry <job-id>
⚠️
Trace job
glab ci trace <job-id>
-
Download artifacts
glab ci artifact
-
Lint CI config
glab ci lint
-
Delete pipeline
glab ci delete <id>
⚠️⚠️
Risk Legend: - Safe | ⚠️ Caution | ⚠️⚠️ Warning | ⚠️⚠️⚠️ Danger
操作命令风险
查看状态
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>
⚠️⚠️
风险说明: - 安全 | ⚠️ 注意 | ⚠️⚠️ 警告 | ⚠️⚠️⚠️ 危险

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:
FlagDescription
-b, --branch=<branch>
Check status for specific branch
-l, --live
Show status in real-time (updates automatically)
-c, --compact
Show compact view
Examples:
bash
undefined
bash
glab ci status [options]
选项:
标识说明
-b, --branch=<branch>
查看指定分支的状态
-l, --live
实时显示状态(自动更新)
-c, --compact
显示精简视图
示例:
bash
undefined

View 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
undefined
glab ci status --compact
undefined

Interactive Pipeline View

交互式流水线查看

bash
glab ci view [options]
Options:
FlagDescription
-b, --branch=<branch>
View pipeline for specific branch/tag
-p, --pipeline-id=<id>
View specific pipeline by ID
-w, --web
Open pipeline in browser
Keyboard shortcuts in view mode:
KeyAction
Esc
or
q
Close logs or return to pipeline
Ctrl+R
or
Ctrl+P
Run, retry, or play a job
Tab
/ Arrow keys
Navigate
Enter
Confirm selection
Ctrl+D
Cancel job / Quit view
Examples:
bash
undefined
bash
glab ci view [options]
选项:
标识说明
-b, --branch=<branch>
查看指定分支/标签的流水线
-p, --pipeline-id=<id>
通过ID查看特定流水线
-w, --web
在浏览器中打开流水线
查看模式下的快捷键:
按键操作
Esc
q
关闭日志或返回流水线视图
Ctrl+R
Ctrl+P
运行、重试或启动作业
Tab
/ 方向键
导航
Enter
确认选择
Ctrl+D
取消作业 / 退出查看模式
示例:
bash
undefined

Interactive 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
undefined
glab ci view --web
undefined

List Pipelines

列出流水线

bash
glab ci list [options]
Options:
FlagDescription
-b, --branch=<branch>
Filter by branch
--status=<status>
Filter by status: running, pending, success, failed, canceled, skipped
--all
List all pipelines (not just default page)
-P, --per-page=<n>
Items per page
Examples:
bash
undefined
bash
glab ci list [options]
选项:
标识说明
-b, --branch=<branch>
按分支过滤
--status=<status>
按状态过滤:running、pending、success、failed、canceled、skipped
--all
列出所有流水线(不只是默认页面)
-P, --per-page=<n>
每页显示条目数
示例:
bash
undefined

List 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
undefined
glab ci list --status=running --all
undefined

Run/Trigger Pipeline

运行/触发流水线

bash
glab ci run [options]
Options:
FlagDescription
-b, --branch=<ref>
Branch or tag to run pipeline on
--variables=<vars>
CI variables as key=value pairs (comma-separated)
Examples:
bash
undefined
bash
glab ci run [options]
选项:
标识说明
-b, --branch=<ref>
运行指定分支或标签的流水线
--variables=<vars>
CI变量,格式为key=value,多组用逗号分隔
示例:
bash
undefined

Run 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
undefined
glab ci run --branch=v1.2.3
undefined

Get Pipeline JSON

获取流水线JSON数据

bash
glab ci get [options]
Get JSON representation of a pipeline.
Options:
FlagDescription
-b, --branch=<branch>
Get pipeline for specific branch
-p, --pipeline-id=<id>
Get specific pipeline by ID
Examples:
bash
undefined
bash
glab ci get [options]
获取流水线的JSON格式数据。
选项:
标识说明
-b, --branch=<branch>
获取指定分支的流水线数据
-p, --pipeline-id=<id>
通过ID获取特定流水线的数据
示例:
bash
undefined

Get 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'
undefined
glab ci get | jq '.status'
undefined

Retry Job

重试作业

bash
glab ci retry <job-id>
Retry a failed CI job.
Examples:
bash
undefined
bash
glab ci retry <job-id>
重试失败的CI作业。
示例:
bash
undefined

Retry specific job

重试指定作业

glab ci retry 456789
undefined
glab ci retry 456789
undefined

Trace Job Logs

追踪作业日志

bash
glab ci trace <job-id> [options]
View job logs in real-time.
Examples:
bash
undefined
bash
glab ci trace <job-id> [options]
实时查看作业日志。
示例:
bash
undefined

Trace job output

追踪作业输出

glab ci trace 456789
undefined
glab ci trace 456789
undefined

Download Artifacts

下载构建产物

bash
glab ci artifact [options]
Download artifacts from the last pipeline.
Options:
FlagDescription
-b, --branch=<branch>
Download from specific branch
-j, --job=<job-name>
Download from specific job
-p, --path=<path>
Download to specific path
Examples:
bash
undefined
bash
glab ci artifact [options]
下载最近一次流水线的构建产物。
选项:
标识说明
-b, --branch=<branch>
从指定分支下载
-j, --job=<job-name>
从指定作业下载
-p, --path=<path>
下载到指定路径
示例:
bash
undefined

Download 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/
undefined
glab ci artifact --path=./artifacts/
undefined

Lint CI Configuration

校验CI配置

bash
glab ci lint [file]
Validate .gitlab-ci.yml file.
Examples:
bash
undefined
bash
glab ci lint [file]
校验.gitlab-ci.yml文件。
示例:
bash
undefined

Lint default .gitlab-ci.yml

校验默认的.gitlab-ci.yml文件

glab ci lint
glab ci lint

Lint specific file

校验指定文件

glab ci lint path/to/.gitlab-ci.yml
undefined
glab ci lint path/to/.gitlab-ci.yml
undefined

Delete 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
undefined
bash
undefined

1. 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
undefined
glab ci status --live
undefined

Workflow 2: Trigger Deployment

工作流2:触发部署

bash
undefined
bash
undefined

1. 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
undefined
glab ci status --live
undefined

Workflow 3: Debug CI Configuration

工作流3:调试CI配置

bash
undefined
bash
undefined

1. 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
undefined
glab ci view
undefined

Workflow 4: Download Build Artifacts

工作流4:下载构建产物

bash
undefined
bash
undefined

1. 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/
undefined
glab ci artifact --branch=release --job=build --path=./dist/
undefined

Pipeline Status Reference

流水线状态参考

StatusMeaning
running
Pipeline is currently executing
pending
Pipeline is waiting to run
success
All jobs passed
failed
One or more jobs failed
canceled
Pipeline was manually canceled
skipped
Pipeline was skipped
manual
Waiting for manual trigger
scheduled
Scheduled to run later
状态含义
running
流水线正在执行
pending
流水线等待执行
success
所有作业执行成功
failed
一个或多个作业执行失败
canceled
流水线被手动取消
skipped
流水线被跳过
manual
等待手动触发
scheduled
已定时,将在稍后运行

Troubleshooting

故障排除

IssueCauseSolution
Authentication failedInvalid/expired tokenRun
glab auth login
Pipeline not foundNo pipeline for branchCheck branch name or run
glab ci run
Job stuck pendingNo runners availableCheck runner configuration
Lint failsInvalid YAML syntaxFix syntax errors in .gitlab-ci.yml
Cannot retryJob not in retryable stateWait for current run or cancel first
问题原因解决方案
认证失败令牌无效/过期运行
glab auth login
重新登录
未找到流水线该分支没有流水线检查分支名称,或运行
glab ci run
触发流水线
作业一直处于等待状态没有可用的运行器检查运行器配置
校验失败YAML语法错误修复.gitlab-ci.yml中的语法错误
无法重试作业作业处于不可重试状态等待当前运行完成或先取消作业

Related Documentation

相关文档

  • Safeguards
  • Quick Reference
  • 安全防护
  • 快速参考