gitlab-ci
它能做什么
这个工具可以帮你使用 GitLab CI/CD 搭建和自动化软件交付流程。你可以创建自动构建、测试和部署代码的步骤。
适用场景
- ✓当你需要搭建 GitLab 的持续交付系统时。
- ✓当你需要定义代码如何被自动测试和部署时。
- ✓当你需要管理运行这些自动化任务的工具时。
技能链接
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/gitlab-ci/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“为我的 Node.js 应用搭建一个流水线,在 main 分支上完成构建、测试和部署。”
每周 5 个新技能,1 分钟读完。
工作原理
你需要在一个名为 `.gitlab-ci.yml` 的文件中定义阶段(stages)和任务(jobs)。这个文件描述了要做什么、按什么顺序做,以及使用哪些工具。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
GitLab CI/CD
Automate your software delivery pipeline with GitLab's integrated CI/CD system.
When to Use This Skill
Use this skill when:
- Setting up CI/CD pipelines in GitLab
- Configuring GitLab runners (shared or self-hosted)
- Creating multi-stage deployment pipelines
- Implementing GitLab Auto DevOps
- Managing CI/CD variables and secrets
Prerequisites
- GitLab repository (gitlab.com or self-hosted)
- Basic understanding of YAML
- For self-hosted runners: Linux server or Kubernetes cluster
Pipeline Configuration
Create .gitlab-ci.yml in repository root:
stages:
- build
- test
- deploy
variables:
NODE_VERSION: "20"
build:
stage: build
image: node:${NODE_VERSION}
script:
- npm ci
- npm run build
artifacts:
paths:
- dist/
expire_in: 1 hour
test:
stage: test
image: node:${NODE_VERSION}
script:
- npm ci
- npm test
coverage: '/Coverage: \d+\.\d+%/'
deploy:
stage: deploy
script:
- ./deploy.sh
environment:
name: production
url: https://example.com
only:
- main
Job Configuration
Rules-Based Execution
deploy:
script: ./deploy.sh
rules:
- if: $CI_COMMIT_BRANCH == "main"
when: manual
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
when: never
- when: on_success
Parallel Jobs
test:
stage: test
parallel: 3
script:
- npm test -- --shard=$CI_NODE_INDEX/$CI_NODE_TOTAL
Matrix Builds
test:
stage: test
parallel:
matrix:
- NODE_VERSION: ["18", "20", "22"]
OS: ["alpine", "slim"]
image: node:${NODE_VERSION}-${OS}
script:
- npm test
Caching
cache:
key:
files:
- package-lock.json
paths:
- node_modules/
policy: pull-push
build:
cache:
key: build-cache
paths:
- .cache/
policy: pull
Artifacts
build:
artifacts:
paths:
- dist/
- coverage/
reports:
junit: junit.xml
coverage_report:
coverage_format: cobertura
path: coverage/cobertura.xml
expire_in: 1 week
when: always
Environments and Deployments
deploy_staging:
stage: deploy
script:
- deploy --env staging
environment:
name: staging
url: https://staging.example.com
on_stop: stop_staging
stop_staging:
stage: deploy
script:
- undeploy --env staging
environment:
name: staging
action: stop
when: manual
Docker Builds
build_image:
stage: build
image: docker:24
services:
- docker:24-dind
variables:
DOCKER_TLS_CERTDIR: "/certs"
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA .
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
GitLab Runners
Install Runner
# Download and install
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash
sudo apt install gitlab-runner
# Register runner
sudo gitlab-runner register \
--url https://gitlab.com/ \
--registration-token TOKEN \
--executor docker \
--docker-image alpine:latest
Runner Configuration
# /etc/gitlab-runner/config.toml
[[runners]]
name = "docker-runner"
url = "https://gitlab.com/"
token = "TOKEN"
executor = "docker"
[runners.docker]
image = "alpine:latest"
privileged = true
volumes = ["/cache", "/var/run/docker.sock:/var/run/docker.sock"]
Runner Tags
build:
tags:
- docker
- linux
script:
- make build
CI/CD Variables
Protected Variables
Define in Settings > CI/CD > Variables:
AWS_ACCESS_KEY_ID(protected, masked)AWS_SECRET_ACCESS_KEY(protected, masked)
Using Variables
deploy:
script:
- aws s3 sync dist/ s3://$S3_BUCKET
variables:
AWS_DEFAULT_REGION: us-east-1
Include and Extend
Include Templates
include:
- template: Security/SAST.gitlab-ci.yml
- project: 'group/shared-ci'
file: '/templates/deploy.yml'
- local: '/ci/jobs.yml'
Extend Jobs
.base_job:
image: node:20
before_script:
- npm ci
build:
extends: .base_job
script:
- npm run build
test:
extends: .base_job
script:
- npm test
Multi-Project Pipelines
trigger_downstream:
stage: deploy
trigger:
project: group/downstream-project
branch: main
…
常见问题
什么是“runner”?
Runner 是执行流水线中定义的任务的代理程序。它们既可以在 GitLab 中配置,也可以部署在你自己的服务器上。
什么是“artifacts”(产物)?
产物是某个任务生成的文件,例如代码构建的输出结果。其他任务可以使用这些文件,你也可以下载它们。
什么是“stages”?
阶段是流水线的主要环节,例如“构建”“测试”和“部署”。同一阶段内的任务会并行运行,不同阶段则按顺序依次运行。
详情
作者的原始描述
Configure GitLab CI/CD pipelines and runners for automated building, testing, and deployment.
热度
- GitHub 星标
- 48k
- 排名
- #4754
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
00-andruia-consultant
48k帮你的智能体启动或改进 AI 项目。它可以分析代码、推荐工具,并用西班牙语制定行动计划。
007
48k让你的智能体执行安全审计和威胁建模。它有助于保护项目免受攻击和漏洞的威胁。
10-andruia-skill-smith
48k帮你的智能体创建或改进 AI 工具。它可以定义工具的工作方式、编写文档,并验证其结构。
20-andruia-niche-intelligence
48k让你的智能体创建某个特定行业的摘要。它有助于借助可靠的信息来源,了解项目的背景、规则、使用模式和风险。