关于 CircleCI CLI
circleci CLI 用于验证 CircleCI 配置文件、在本地环境执行流水线作业,以及管理 orb。开发者可以在提交前测试配置和作业,加快反馈循环。
主要功能
- 01验证 CircleCI 配置文件的正确性
- 02在本地环境运行流水线作业进行测试
- 03搜索和管理 CircleCI orb
适用场景
- 01在开发过程中快速迭代和测试 CI/CD 配置
- 02验证配置更改后再推送到远程仓库
安装
选择你的系统或包管理器,复制命令到终端运行。
安装完成后运行circleci --version确认安装成功。
命令示例
常用命令按使用顺序排列。
详细介绍
circleci-cli
这是 CircleCI 的命令行应用程序。
circleci 是 CircleCI 官方的命令行工具。这是一款对 Agent 友好的 CLI,可将 CI 运行、作业、配置和其他 CircleCI 功能带到你正在使用的终端中。
此 CLI 面向 circleci.com 和 CircleCI 服务的用户提供支持,并支持 macOS、Windows 和 Linux。
安装
通过以下任一软件包管理器安装 CLI:
Homebrew
brew install circleci
WinGet
winget install --id CircleCI.CLI
Snap
sudo snap install circleci
sudo snap connect circleci:password-manager-service
Debian
Debian 软件包托管在 packages.circleci.com,支持多种操作系统,包括:
要安装软件包,可以快速自动设置软件源:
curl -1sLf 'https://packages.circleci.com/public/setup.deb.sh' | sudo -E bash
或者,你也可以在安装软件包前手动配置软件源:
apt-get install -y debian-keyring # debian only
apt-get install -y debian-archive-keyring # debian only
apt-get install -y apt-transport-https
# For Debian Stretch, Ubuntu 16.04 and later
keyring_location=/usr/share/keyrings/circleci-deps-public-archive-keyring.gpg
# For Debian Jessie, Ubuntu 15.10 and earlier
keyring_location=/etc/apt/trusted.gpg.d/circleci-deps-public.gpg
curl -1sLf 'https://packages.circleci.com/public/gpg.B3F71F41836351D6.key' | gpg --dearmor >> ${keyring_location}
curl -1sLf 'https://packages.circleci.com/public/config.deb.txt?distro=ubuntu&codename=xenial&component=main' > /etc/apt/sources.list.d/circleci-deps-public.list
sudo chmod 644 ${keyring_location}
sudo chmod 644 /etc/apt/sources.list.d/circleci-deps-public.list
apt-get update
注意:请将上面的 ubuntu、xenial 和 main 替换为你实际的操作系统(发行版及其发行版本)和组件(根据此软件源中的内容)。
然后安装:
sudo apt install circleci
RedHat
RPM 软件包托管在 packages.circleci.com,支持多种操作系统,包括:
对于大多数基于 RPM 的发行版(RHEL、CentOS、Fedora、SUSE),你可以快速自动设置软件源:
curl -1sLf 'https://packages.circleci.com/public/setup.rpm.sh' | sudo -E bash
或者,手动设置 Yum(RHEL、CentOS、Amazon Linux):
yum install yum-utils pygpgme
rpm --import 'https://packages.circleci.com/public/gpg.B3F71F41836351D6.key'
curl -1sLf 'https://packages.circleci.com/public/config.rpm.txt?distro=el&codename=7' > /tmp/circleci-deps-public.repo
yum-config-manager --add-repo '/tmp/circleci-deps-public.repo'
yum -q makecache -y --disablerepo='*' --enablerepo='circleci-deps-public'
注意:请将上面的 el 和 7 替换为你实际的发行版/版本;启用多个软件源时请使用通配符。
或者,手动设置 DNF(Fedora):
dnf install yum-utils pygpgme
rpm --import 'https://packages.circleci.com/public/gpg.B3F71F41836351D6.key'
curl -1sLf 'https://packages.circleci.com/public/config.rpm.txt?distro=fedora&codename=29&dnf_version=5' > /tmp/circleci-deps-public.repo
dnf config-manager addrepo --from-repofile='/tmp/circleci-deps-public.repo'
dnf -q makecache -y --disablerepo='*' --enablerepo='circleci-deps-public' --enablerepo='circleci-deps-public-source'
注意:请将 fedora 和 29 替换为你实际的发行版/版本。
然后安装:
dnf install circleci
或者:
yum install circleci
设置
登录
运行以下命令登录 CircleCI CLI:
circleci auth login
Model Context Protocol (MCP)
CLI 支持 MCP 协议。要启用此协议,请运行:
Claude:
circleci mcp claude enable # Enable in Claude desktop
claude mcp add-from-claude-desktop -s user # Add with current user scope
Cursor:
circleci mcp cursor enable
VS Code:
circleci mcp vscode enable
开发
本地开发
此代码库使用 Task,可通过以下命令在 MacOS 上安装:
$ brew install go-task/tap/go-task
Taskfile.yml 中引用的大多数其他工具都由 go.mod 的工具部分管理。
运行 task -l 查看可用任务的完整列表,或者查看 Taskfile.yml 脚本。
# Run all static checks
task check
# Auto-fix static checks
task fix
# Run all the tests
task test
# Run the quick tests
task test -- -short ./...
# Run the quick tests for one package
task test -- -short ./internal/...
# Format all the code
task fmt
# Apply license headers
task license
# Tidy go.mod
task mod-tidy