jk
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseJenkins CLI (jk)
Jenkins CLI (jk)
jkjkDependency Check
依赖检查
Before executing any command, verify the CLI is installed:
jkbash
jk --versionIf the command fails or is not found, install it using one of these methods:
jk| Platform | Command |
|---|---|
| macOS/Linux | |
| Windows | |
| Go | |
| Binary | Download from GitHub Releases |
Only proceed with commands after confirming installation succeeds.
jk在执行任何命令之前,请验证CLI是否已安装:
jkbash
jk --version如果命令执行失败或未找到,请通过以下方式之一安装:
jk| 平台 | 命令 |
|---|---|
| macOS/Linux | |
| Windows | |
| Go | |
| 二进制包 | 从GitHub Releases下载 |
确认安装成功后,再继续执行命令。
jkAuthentication
身份认证
bash
undefinedbash
undefinedLogin with credentials
使用凭据登录
jk auth login https://jenkins.example.com --username alice --token <API_TOKEN>
jk auth login https://jenkins.example.com --username alice --token <API_TOKEN>
Login with custom context name
使用自定义上下文名称登录
jk auth login https://jenkins.example.com --name prod --username alice --token <TOKEN>
jk auth login https://jenkins.example.com --name prod --username alice --token <TOKEN>
Login with TLS options
使用TLS选项登录
jk auth login https://jenkins.example.com --username alice --token <TOKEN> --insecure
jk auth login https://jenkins.example.com --username alice --token <TOKEN> --ca-file /path/to/ca.pem
jk auth login https://jenkins.example.com --username alice --token <TOKEN> --insecure
jk auth login https://jenkins.example.com --username alice --token <TOKEN> --ca-file /path/to/ca.pem
Check auth status (active context)
检查认证状态(当前活跃上下文)
jk auth status
jk auth status
Logout from a context
退出某个上下文的登录
jk auth logout # Logout from active context
jk auth logout prod # Logout from specific context
Options for `auth login`:
- `--name` — Context name (defaults to hostname)
- `--username` — Jenkins username
- `--token` — API token
- `--insecure` — Skip TLS verification
- `--proxy` — Proxy URL
- `--ca-file` — Custom CA bundle
- `--set-active` — Set as active context (default: true)
- `--allow-insecure-store` — Allow encrypted file fallbackjk auth logout # 退出当前活跃上下文的登录
jk auth logout prod # 退出指定上下文的登录
`auth login`的可用选项:
- `--name` — 上下文名称(默认值为主机名)
- `--username` — Jenkins用户名
- `--token` — API令牌
- `--insecure` — 跳过TLS验证
- `--proxy` — 代理URL
- `--ca-file` — 自定义CA证书包
- `--set-active` — 设置为活跃上下文(默认值:true)
- `--allow-insecure-store` — 允许使用加密文件作为备选存储Contexts
上下文管理
Contexts store controller URLs and credentials for easy switching:
bash
undefined上下文用于存储控制器URL和凭据,方便快速切换:
bash
undefinedList contexts (* = active)
列出所有上下文(* = 活跃上下文)
jk context ls
jk context ls
Switch active context
切换活跃上下文
jk context use prod-jenkins
jk context use prod-jenkins
Remove a context
删除一个上下文
jk context rm staging
Environment: `JK_CONTEXT` overrides active context.jk context rm staging
环境变量:`JK_CONTEXT`可覆盖当前活跃上下文。Quick Command Reference
快速命令参考
| Task | Command |
|---|---|
| Search jobs | |
| List jobs | |
| View job | |
| List runs | |
| Start run | |
| View run | |
| Follow logs | |
| Stream logs | |
| Download artifacts | |
| Test report | |
| List credentials | |
| List nodes | |
| View queue | |
| List plugins | |
| 任务 | 命令 |
|---|---|
| 搜索任务 | |
| 列出任务 | |
| 查看任务详情 | |
| 列出运行实例 | |
| 启动运行实例 | |
| 查看运行实例详情 | |
| 实时查看日志 | |
| 流式传输日志 | |
| 下载制品 | |
| 查看测试报告 | |
| 列出凭据 | |
| 列出节点 | |
| 查看队列 | |
| 列出插件 | |
Job Discovery
任务发现
bash
undefinedbash
undefinedSearch across folders
跨文件夹搜索任务
jk search --job-glob 'deploy' --limit 10
jk search --job-glob 'deploy' --limit 10
Search in specific folder
在指定文件夹内搜索任务
jk search --folder team/services --job-glob 'api'
jk search --folder team/services --job-glob 'api'
Filter by run results
按运行结果过滤
jk search --job-glob '*' --filter result=FAILURE --since 7d
jk search --job-glob '*' --filter result=FAILURE --since 7d
With parameter filters
按参数过滤
jk search --job-glob '/deploy-' --filter param.ENV=production
undefinedjk search --job-glob '/deploy-' --filter param.ENV=production
undefinedJob Operations
任务操作
bash
undefinedbash
undefinedList jobs in root
列出根目录下的任务
jk job ls
jk job ls
List jobs in folder (positional or flag)
列出指定文件夹内的任务(位置参数或标志参数)
jk job ls team/app
jk job ls --folder team/app
jk job ls team/app
jk job ls --folder team/app
View job details
查看任务详情
jk job view team/app/pipeline
undefinedjk job view team/app/pipeline
undefinedRun Management
运行实例管理
Listing Runs
列出运行实例
bash
undefinedbash
undefinedList recent runs
列出最近的运行实例
jk run ls team/app/pipeline
jk run ls team/app/pipeline
Limit results
限制结果数量
jk run ls team/app/pipeline --limit 50
jk run ls team/app/pipeline --limit 50
Filter runs
过滤运行实例
jk run ls team/app/pipeline --filter result=SUCCESS
jk run ls team/app/pipeline --filter result=FAILURE --since 7d
jk run ls team/app/pipeline --filter result=SUCCESS
jk run ls team/app/pipeline --filter result=FAILURE --since 7d
Filter by parameters
按参数过滤
jk run ls team/app/pipeline --filter param.ENV=staging
jk run ls team/app/pipeline --filter param.ENV=staging
Include queued builds
包含排队中的构建任务
jk run ls team/app/pipeline --include-queued
jk run ls team/app/pipeline --include-queued
Group by parameter
按参数分组
jk run ls team/app/pipeline --group-by param.ENV --agg last
jk run ls team/app/pipeline --group-by param.ENV --agg last
With metadata for agents
包含代理节点的元数据
jk run ls team/app/pipeline --json --with-meta
jk run ls team/app/pipeline --json --with-meta
Pagination
分页查询
jk run ls team/app/pipeline --cursor <cursor-from-previous>
undefinedjk run ls team/app/pipeline --cursor <cursor-from-previous>
undefinedStarting Runs
启动运行实例
bash
undefinedbash
undefinedStart a run
启动一个运行实例
jk run start team/app/pipeline
jk run start team/app/pipeline
Start with parameters
带参数启动
jk run start team/app/pipeline -p BRANCH=main -p ENV=staging
jk run start team/app/pipeline -p BRANCH=main -p ENV=staging
Start and follow logs
启动并实时查看日志
jk run start team/app/pipeline --follow
jk run start team/app/pipeline --follow
Start, wait for completion (no log streaming)
启动并等待完成(不流式传输日志)
jk run start team/app/pipeline --wait --timeout 10m
jk run start team/app/pipeline --wait --timeout 10m
Get only the result
仅获取运行结果
jk run start team/app/pipeline --follow --result
jk run start team/app/pipeline --follow --result
Fuzzy job matching
模糊匹配任务名称启动
jk run start deploy --fuzzy
undefinedjk run start deploy --fuzzy
undefinedViewing Runs
查看运行实例详情
bash
undefinedbash
undefinedView run details
查看运行实例详情
jk run view team/app/pipeline 128
jk run view team/app/pipeline 128
Get only result status
仅获取结果状态
jk run view team/app/pipeline 128 --result
jk run view team/app/pipeline 128 --result
Exit with build result code
以构建结果作为退出码
jk run view team/app/pipeline 128 --exit-status
jk run view team/app/pipeline 128 --exit-status
Wait for completion
等待运行实例完成
jk run view team/app/pipeline 128 --wait --timeout 5m
jk run view team/app/pipeline 128 --wait --timeout 5m
Show summary
显示摘要信息
jk run view team/app/pipeline 128 --summary
undefinedjk run view team/app/pipeline 128 --summary
undefinedOther Run Commands
其他运行实例命令
bash
undefinedbash
undefinedView run parameters
查看运行实例参数
jk run params team/app/pipeline
jk run params team/app/pipeline
Cancel a run
取消运行实例
jk run cancel team/app/pipeline 128
jk run cancel team/app/pipeline 128 --mode term
jk run cancel team/app/pipeline 128 --mode kill
jk run cancel team/app/pipeline 128
jk run cancel team/app/pipeline 128 --mode term
jk run cancel team/app/pipeline 128 --mode kill
Rerun a build (with same parameters)
重新运行构建(使用相同参数)
jk run rerun team/app/pipeline 128
jk run rerun team/app/pipeline 128 --follow
undefinedjk run rerun team/app/pipeline 128
jk run rerun team/app/pipeline 128 --follow
undefinedLogs
日志管理
bash
undefinedbash
undefinedView console log (snapshot)
查看控制台日志(快照)
jk log team/app/pipeline 128
jk log team/app/pipeline 128
Stream live logs
实时流式传输日志
jk log team/app/pipeline 128 --follow
jk log team/app/pipeline 128 --follow
Custom poll interval
自定义轮询间隔
jk log team/app/pipeline 128 --follow --interval 2s
jk log team/app/pipeline 128 --follow --interval 2s
Plain output (no decorations)
纯文本输出(无装饰格式)
jk log team/app/pipeline 128 --plain
undefinedjk log team/app/pipeline 128 --plain
undefinedArtifacts
制品管理
bash
undefinedbash
undefinedList artifacts
列出制品
jk artifact ls team/app/pipeline 128
jk artifact ls team/app/pipeline 128
Download all artifacts
下载所有制品
jk artifact download team/app/pipeline 128
jk artifact download team/app/pipeline 128
Download with pattern filter
按模式过滤下载
jk artifact download team/app/pipeline 128 --pattern "/*.jar"
jk artifact download team/app/pipeline 128 -p "reports//*.xml"
jk artifact download team/app/pipeline 128 --pattern "/*.jar"
jk artifact download team/app/pipeline 128 -p "reports//*.xml"
Output directory
指定输出目录
jk artifact download team/app/pipeline 128 -o ./artifacts/
jk artifact download team/app/pipeline 128 -o ./artifacts/
Allow empty result (no error if no matches)
允许空结果(无匹配时不报错)
jk artifact download team/app/pipeline 128 -p "*.log" --allow-empty
undefinedjk artifact download team/app/pipeline 128 -p "*.log" --allow-empty
undefinedTest Results
测试结果
bash
undefinedbash
undefinedView test report
查看测试报告
jk test report team/app/pipeline 128
jk test report team/app/pipeline 128
JSON output
JSON格式输出
jk test report team/app/pipeline 128 --json
undefinedjk test report team/app/pipeline 128 --json
undefinedCredentials
凭据管理
bash
undefinedbash
undefinedList credentials (system scope)
列出凭据(系统范围)
jk cred ls
jk cred ls
List folder-scoped credentials
列出文件夹范围的凭据
jk cred ls --scope folder --folder team/app
jk cred ls --scope folder --folder team/app
Create secret text
创建文本凭据
jk cred create-secret --id my-secret --secret "value"
jk cred create-secret --id my-secret --secret "value" --description "API key"
jk cred create-secret --id my-secret --secret "value"
jk cred create-secret --id my-secret --secret "value" --description "API key"
Create from stdin
从标准输入创建凭据
echo "secret-value" | jk cred create-secret --id my-secret --from-stdin
echo "secret-value" | jk cred create-secret --id my-secret --from-stdin
Folder-scoped credential
创建文件夹范围的凭据
jk cred create-secret --id my-secret --secret "value" --scope folder --folder team/app
jk cred create-secret --id my-secret --secret "value" --scope folder --folder team/app
Delete credential (system scope only)
删除凭据(仅支持系统范围)
jk cred rm my-secret
undefinedjk cred rm my-secret
undefinedNode Management
节点管理
bash
undefinedbash
undefinedList nodes
列出节点
jk node ls
jk node ls
Cordon node (mark temporarily offline)
标记节点为不可调度(临时下线)
jk node cordon agent-01
jk node cordon agent-01 --message "Maintenance"
jk node cordon agent-01
jk node cordon agent-01 --message "Maintenance"
Uncordon node (bring back online)
标记节点为可调度(重新上线)
jk node uncordon agent-01
jk node uncordon agent-01
Remove node
删除节点
jk node rm agent-01
undefinedjk node rm agent-01
undefinedQueue Management
队列管理
bash
undefinedbash
undefinedList queued items
列出排队中的任务
jk queue ls
jk queue ls
Cancel queued item
取消排队中的任务
jk queue cancel <item-id>
undefinedjk queue cancel <item-id>
undefinedPlugin Management
插件管理
bash
undefinedbash
undefinedList installed plugins
列出已安装的插件
jk plugin ls
jk plugin ls
Install plugin (prompts for confirmation)
安装插件(需确认)
jk plugin install docker-workflow
jk plugin install docker-workflow
Install without confirmation
无确认直接安装
jk plugin install docker-workflow --yes
jk plugin install docker-workflow --yes
Install specific version
安装指定版本的插件
jk plugin install docker-workflow@1.26
jk plugin install docker-workflow@1.26
Enable/disable plugin
启用/禁用插件
jk plugin enable docker-workflow
jk plugin disable docker-workflow
undefinedjk plugin enable docker-workflow
jk plugin disable docker-workflow
undefinedOutput Modes
输出模式
All commands support structured output:
bash
undefined所有命令均支持结构化输出:
bash
undefinedJSON output
JSON格式输出
jk run ls team/app --json
jk run ls team/app --json
YAML output
YAML格式输出
jk run ls team/app --yaml
jk run ls team/app --yaml
Filter with jq expression
使用jq表达式过滤
jk run ls team/app --json --jq '.items[0].number'
jk run ls team/app --json --jq '.items[0].number'
Go template
使用Go模板格式化
jk run ls team/app --json --template '{{range .items}}{{.number}}{{end}}'
jk run ls team/app --json --template '{{range .items}}{{.number}}{{end}}'
Quiet mode (minimal output)
静默模式(仅输出必要信息)
jk run start team/app --quiet
undefinedjk run start team/app --quiet
undefinedGlobal Options
全局选项
- — Use specific context
-c, --context <name> - — JSON output
--json - — YAML output
--yaml - — Output format
--format json|yaml - — Filter JSON with jq expression
--jq <expr> - — Format with Go template
-t, --template <tmpl> - — Suppress non-essential output
-q, --quiet
- — 使用指定的上下文
-c, --context <name> - — JSON格式输出
--json - — YAML格式输出
--yaml - — 指定输出格式
--format json|yaml - — 使用jq表达式过滤JSON
--jq <expr> - — 使用Go模板格式化输出
-t, --template <tmpl> - — 抑制非必要输出
-q, --quiet
Environment Variables
环境变量
- — Override active context
JK_CONTEXT
- — 覆盖当前活跃上下文
JK_CONTEXT
Exit Codes
退出码
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | General error |
| 2 | Validation error |
| 3 | Not found |
| 4 | Authentication failure |
| 5 | Permission denied |
| 6 | Connectivity failure |
| 7 | Timeout |
| 8 | Feature unsupported |
With or , build results use additional codes:
--follow--wait| Code | Result |
|---|---|
| 0 | SUCCESS |
| 10 | UNSTABLE |
| 11 | FAILURE |
| 12 | ABORTED |
| 13 | NOT_BUILT |
| 14 | RUNNING |
| 代码 | 含义 |
|---|---|
| 0 | 成功 |
| 1 | 通用错误 |
| 2 | 验证错误 |
| 3 | 未找到资源 |
| 4 | 身份认证失败 |
| 5 | 权限不足 |
| 6 | 连接失败 |
| 7 | 超时 |
| 8 | 功能不支持 |
使用或时,构建结果会使用额外的退出码:
--follow--wait| 代码 | 结果 |
|---|---|
| 0 | SUCCESS(成功) |
| 10 | UNSTABLE(不稳定) |
| 11 | FAILURE(失败) |
| 12 | ABORTED(已中止) |
| 13 | NOT_BUILT(未构建) |
| 14 | RUNNING(运行中) |
References
参考资料
- Full command reference: See references/commands.md
- 完整命令参考:查看references/commands.md