jk

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Jenkins CLI (jk)

Jenkins CLI (jk)

jk
is a GitHub CLI–style interface for Jenkins controllers. It provides modern, scriptable workflows for developers and operators.
jk
是一款类GitHub CLI风格的Jenkins控制器界面,为开发人员和运维人员提供现代化的、可脚本化的工作流。

Dependency Check

依赖检查

Before executing any
jk
command
, verify the CLI is installed:
bash
jk --version
If the command fails or
jk
is not found, install it using one of these methods:
PlatformCommand
macOS/Linux
brew install avivsinai/tap/jk
Windows
scoop bucket add avivsinai https://github.com/avivsinai/scoop-bucket && scoop install jk
Go
go install github.com/avivsinai/jenkins-cli/cmd/jk@latest
BinaryDownload from GitHub Releases
Only proceed with
jk
commands after confirming installation succeeds.
在执行任何
jk
命令之前
,请验证CLI是否已安装:
bash
jk --version
如果命令执行失败或未找到
jk
,请通过以下方式之一安装:
平台命令
macOS/Linux
brew install avivsinai/tap/jk
Windows
scoop bucket add avivsinai https://github.com/avivsinai/scoop-bucket && scoop install jk
Go
go install github.com/avivsinai/jenkins-cli/cmd/jk@latest
二进制包GitHub Releases下载
确认安装成功后,再继续执行
jk
命令。

Authentication

身份认证

bash
undefined
bash
undefined

Login 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 fallback
jk 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
undefined

List 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

快速命令参考

TaskCommand
Search jobs
jk search --job-glob '*deploy*'
List jobs
jk job ls
View job
jk job view team/app
List runs
jk run ls team/app
Start run
jk run start team/app -p KEY=value
View run
jk run view team/app 128
Follow logs
jk run start team/app --follow
Stream logs
jk log team/app 128 --follow
Download artifacts
jk artifact download team/app 128
Test report
jk test report team/app 128
List credentials
jk cred ls
List nodes
jk node ls
View queue
jk queue ls
List plugins
jk plugin ls
任务命令
搜索任务
jk search --job-glob '*deploy*'
列出任务
jk job ls
查看任务详情
jk job view team/app
列出运行实例
jk run ls team/app
启动运行实例
jk run start team/app -p KEY=value
查看运行实例详情
jk run view team/app 128
实时查看日志
jk run start team/app --follow
流式传输日志
jk log team/app 128 --follow
下载制品
jk artifact download team/app 128
查看测试报告
jk test report team/app 128
列出凭据
jk cred ls
列出节点
jk node ls
查看队列
jk queue ls
列出插件
jk plugin ls

Job Discovery

任务发现

bash
undefined
bash
undefined

Search 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
undefined
jk search --job-glob '/deploy-' --filter param.ENV=production
undefined

Job Operations

任务操作

bash
undefined
bash
undefined

List 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
undefined
jk job view team/app/pipeline
undefined

Run Management

运行实例管理

Listing Runs

列出运行实例

bash
undefined
bash
undefined

List 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>
undefined
jk run ls team/app/pipeline --cursor <cursor-from-previous>
undefined

Starting Runs

启动运行实例

bash
undefined
bash
undefined

Start 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
undefined
jk run start deploy --fuzzy
undefined

Viewing Runs

查看运行实例详情

bash
undefined
bash
undefined

View 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
undefined
jk run view team/app/pipeline 128 --summary
undefined

Other Run Commands

其他运行实例命令

bash
undefined
bash
undefined

View 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
undefined
jk run rerun team/app/pipeline 128 jk run rerun team/app/pipeline 128 --follow
undefined

Logs

日志管理

bash
undefined
bash
undefined

View 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
undefined
jk log team/app/pipeline 128 --plain
undefined

Artifacts

制品管理

bash
undefined
bash
undefined

List 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
undefined
jk artifact download team/app/pipeline 128 -p "*.log" --allow-empty
undefined

Test Results

测试结果

bash
undefined
bash
undefined

View 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
undefined
jk test report team/app/pipeline 128 --json
undefined

Credentials

凭据管理

bash
undefined
bash
undefined

List 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
undefined
jk cred rm my-secret
undefined

Node Management

节点管理

bash
undefined
bash
undefined

List 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
undefined
jk node rm agent-01
undefined

Queue Management

队列管理

bash
undefined
bash
undefined

List queued items

列出排队中的任务

jk queue ls
jk queue ls

Cancel queued item

取消排队中的任务

jk queue cancel <item-id>
undefined
jk queue cancel <item-id>
undefined

Plugin Management

插件管理

bash
undefined
bash
undefined

List 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
undefined
jk plugin enable docker-workflow jk plugin disable docker-workflow
undefined

Output Modes

输出模式

All commands support structured output:
bash
undefined
所有命令均支持结构化输出:
bash
undefined

JSON 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
undefined
jk run start team/app --quiet
undefined

Global Options

全局选项

  • -c, --context <name>
    — Use specific context
  • --json
    — JSON output
  • --yaml
    — YAML output
  • --format json|yaml
    — Output format
  • --jq <expr>
    — Filter JSON with jq expression
  • -t, --template <tmpl>
    — Format with Go template
  • -q, --quiet
    — Suppress non-essential output
  • -c, --context <name>
    — 使用指定的上下文
  • --json
    — JSON格式输出
  • --yaml
    — YAML格式输出
  • --format json|yaml
    — 指定输出格式
  • --jq <expr>
    — 使用jq表达式过滤JSON
  • -t, --template <tmpl>
    — 使用Go模板格式化输出
  • -q, --quiet
    — 抑制非必要输出

Environment Variables

环境变量

  • JK_CONTEXT
    — Override active context
  • JK_CONTEXT
    — 覆盖当前活跃上下文

Exit Codes

退出码

CodeMeaning
0Success
1General error
2Validation error
3Not found
4Authentication failure
5Permission denied
6Connectivity failure
7Timeout
8Feature unsupported
With
--follow
or
--wait
, build results use additional codes:
CodeResult
0SUCCESS
10UNSTABLE
11FAILURE
12ABORTED
13NOT_BUILT
14RUNNING
代码含义
0成功
1通用错误
2验证错误
3未找到资源
4身份认证失败
5权限不足
6连接失败
7超时
8功能不支持
使用
--follow
--wait
时,构建结果会使用额外的退出码:
代码结果
0SUCCESS(成功)
10UNSTABLE(不稳定)
11FAILURE(失败)
12ABORTED(已中止)
13NOT_BUILT(未构建)
14RUNNING(运行中)

References

参考资料

  • Full command reference: See references/commands.md
  • 完整命令参考:查看references/commands.md