chaoz的杂货铺

生命有息、学无止境、折腾不止

0%

Jenkins Pipeline

pipeline 简介

将原本独立运行于单个或者多个节点的任务连接起来,实现单个任务难以完成的复杂流程编排与可视化。

Pipeline 提供了一组可扩展的工具,通过 Pipeline Domain Specific Language(DSL)syntax 可以达到 Pipeline as Code(Jenkinsfile 存储在项目的源代码库)的目的。

1
2
3
4
5
6
Pipeline五大特性:
代码: Pipeline 以代码的形式实现,通常被检入源代码控制,使团队能够编辑、审查和迭代其CD流程。
可持续性:Jenklins 重启或者中断后都不会影响Pipeline Job。
停顿:Pipeline 可以选择停止并等待任工输入或批准,然后再继续Pipeline运行。
多功能:Pipeline 持现实复杂CD要求,包括fork/join子进程,循环和并行执行工作的能力
可扩展:Pipeline 插件支持其DSL的自定义扩展以及与其他插件集成的多个选项。

1
2
3
支持两种语法
Declarative 声明式(在Pipeline plugin 2.5中引入)
Scripted Pipeline 脚本式

推荐在Jenkins中直接从源代码控制(SCM)中载入Jenklinsfile Pipeline,而不是直接在Jenkins Web UI 网页界面中输入脚本

jenkins shell 可用参数

可用传参官方文档

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
The following variables are available to shell scripts
Shell 脚本可以使用以下变量

BRANCH_NAME 分支名称
For a multibranch project, this will be set to the name of the branch being built, for example in case you wish to deploy to production from master but not from feature branches; if corresponding to some kind of change request, the name is generally arbitrary (refer to CHANGE_ID and CHANGE_TARGET).
对于多分支项目,这将设置为正在构建的分支的名称,例如,如果您希望从但不是来自特性分支; 如果对应某种类型的更改请求,名称通常是任意的(参见CHANGE_ID and 及CHANGE_TARGET).

CHANGE_ID 更改 id
For a multibranch project corresponding to some kind of change request, this will be set to the change ID, such as a pull request number, if supported; else unset.
对于与某种类型的更改请求相对应的多分支项目,这将设置为更改 ID,如果支持,则设置为拉请求编号; 否则取消设置

CHANGE_URL 更改网址
For a multibranch project corresponding to some kind of change request, this will be set to the change URL, if supported; else unset.
对于与某种更改请求相对应的多分支项目,如果支持,则将其设置为更改 URL; else 取消设置

CHANGE_TITLE 更改标题
For a multibranch project corresponding to some kind of change request, this will be set to the title of the change, if supported; else unset.
对于与某种更改请求相对应的多分支项目,如果支持,则将其设置为更改的标题; 否则不设置

CHANGE_AUTHOR 改变作者
For a multibranch project corresponding to some kind of change request, this will be set to the username of the author of the proposed change, if supported; else unset.
对于与某种更改请求相对应的多分支项目,如果支持,这将设置为提议更改的作者的用户名; 否则取消设置

CHANGE_AUTHOR_DISPLAY_NAME 更改作者显示名称
For a multibranch project corresponding to some kind of change request, this will be set to the human name of the author, if supported; else unset.
对于与某种更改请求相对应的多分支项目,如果支持,则将其设置为作者的人名; 否则不设置

CHANGE_AUTHOR_EMAIL 更改作者电子邮件
For a multibranch project corresponding to some kind of change request, this will be set to the email address of the author, if supported; else unset.
对于与某种更改请求相对应的多分支项目,如果支持,则将其设置为作者的电子邮件地址; 否则不设置

CHANGE_TARGET 改变目标
For a multibranch project corresponding to some kind of change request, this will be set to the target or base branch to which the change could be merged, if supported; else unset.
对于与某种更改请求相对应的多分支项目,如果支持,则将其设置为可将更改合并到的目标分支或基本分支; 否则不设置

BUILD_NUMBER 建筑编号
The current build number, such as "153"
当前的生成编号,如“153”

BUILD_ID 建立 id
The current build ID, identical to BUILD_NUMBER for builds created in 1.597+, but a YYYY-MM-DD_hh-mm-ss timestamp for older builds
当前的构建 ID 与在1.597 + 中创建的构建版本的 BUILD number 相同,但是对于较早的构建版本是 YYYY-MM-DD hh-mm-ss 时间戳

BUILD_DISPLAY_NAME 建立显示名称
The display name of the current build, which is something like "#153" by default.
当前版本的显示名称,默认情况下类似于“ # 153”

JOB_NAME 职位名称
Name of the project of this build, such as "foo" or "foo/bar".
此构建的项目名称,如“ foo”或“ foo / bar”

JOB_BASE_NAME 作业库名称
Short Name of the project of this build stripping off folder paths, such as "foo" for "bar/foo".
这个剥离文件夹路径的项目的简称,比如“ bar / foo”的“ foo”

BUILD_TAG 构建标签
String of "jenkins- “ jenkins-${JOB_NAME} ${ JOB name }-${BUILD_NUMBER} ${ BUILD number }". All forward slashes ("/") in the JOB_NAME are replaced with dashes ("-"). Convenient to put into a resource file, a jar file, etc for easier identification. ".
作业名称中的所有前向斜杠(“ / ”)都将替换为破折号(“-”)。 方便地放入资源文件、 jar 文件等,以便于识别

EXECUTOR_NUMBER 遗嘱执行人编号
The unique number that identifies the current executor (among executors of the same machine) that’s carrying out this build. This is the number you see in the "build executor status", except that the number starts from 0, not 1.
标识执行此构建的当前执行器(在同一机器的执行器之间)的唯一编号。 这是您在“构建执行器状态”中看到的数字,但是这个数字是从0开始的,而不是1

NODE_NAME 节点名称
Name of the agent if the build is on an agent, or "master" if run on master
如果生成在代理上,则为代理的名称; 如果在主机上运行,则为“ master”

NODE_LABELS 节点标签
Whitespace-separated list of labels that the node is assigned.
以空格分隔的节点所分配的标签列表

WORKSPACE 工作区
The absolute path of the directory assigned to the build as a workspace.
分配给生成作为工作区的目录的绝对路径

JENKINS_HOME
The absolute path of the directory assigned on the master node for Jenkins to store data.
在主节点上为 Jenkins 存储数据分配的目录的绝对路径

JENKINS_URL
Full URL of Jenkins, like http://server:port/jenkins/ (note: only available if Jenkins URL set in system configuration)
完整的 Jenkins 网址,比如http://server:port/jenkins/ (注: 只有在下列情况才可使用:Jenkins URL 设定为系统配置)

BUILD_URL 建立网址
Full URL of this build, like http://server:port/jenkins/job/foo/15/ (Jenkins URL must be set)
这个版本的完整 URL,比如 http://server:port/jenkins/job/foo/15/ (Jenkins URL 必须设置)

JOB_URL 工作网址
Full URL of this job, like http://server:port/jenkins/job/foo/ (Jenkins URL must be set)
这个工作的完整网址,像 http://server:port/jenkins/job/foo/ (Jenkins URL must be set)

GIT_COMMIT
The commit hash being checked out.
正在签出提交散列

GIT_PREVIOUS_COMMIT 上一次提交
The hash of the commit last built on this branch, if any.
提交的散列最后构建在此分支上(如果有的话)

GIT_PREVIOUS_SUCCESSFUL_COMMIT 上一次成功提交
The hash of the commit last successfully built on this branch, if any.
提交的散列最后一次成功构建在此分支上(如果有的话)

GIT_BRANCH
The remote branch name, if any.
远程分支名称(如果有的话)

GIT_LOCAL_BRANCH
The local branch name being checked out, if applicable.
正在检出的本地分支名称(如果适用)

GIT_CHECKOUT_DIR
The directory that the repository will be checked out to. This contains the value set in Checkout to a sub-directory, if used.
将要签出存储库的目录。 这包含签出到子目录中设置的值(如果使用)

GIT_URL Git url
The remote URL. If there are multiple, will be GIT_URL_1, GIT_URL_2, etc.
远程 URL。如果有多个,将GIT_URL_1, GIT_URL_2, etc. 等等

GIT_COMMITTER_NAME
The configured Git committer name, if any, that will be used for FUTURE commits from the current workspace. It is read from the Global Config user.name Value field of the Jenkins Configure System page.
配置的 Git committer 名称(如果有的话)将用于当前工作区的 FUTURE 提交。 它是从Global Config user.name Value field of the Jenkins 詹金斯的领域Configure System 配置系统 page. 页

GIT_AUTHOR_NAME
The configured Git author name, if any, that will be used for FUTURE commits from the current workspace. It is read from the Global Config user.name Value field of the Jenkins Configure System page.
已配置的 Git 作者名(如果有的话)将用于当前工作区的 FUTURE 提交。 它是从Global Config user.name Value field of the Jenkins 詹金斯的领域Configure System 配置系统 page. 页

GIT_COMMITTER_EMAIL
The configured Git committer email, if any, that will be used for FUTURE commits from the current workspace. It is read from the Global Config user.email Value field of the Jenkins Configure System page.
配置的 Git 提交器电子邮件(如果有的话)将用于当前工作区的 FUTURE 提交。 它是从Global Config user.email Value 全局配置 user.email 值 field of the Jenkins 詹金斯的领域Configure System 配置系统 page. 页

GIT_AUTHOR_EMAIL
The configured Git author email, if any, that will be used for FUTURE commits from the current workspace. It is read from the Global Config user.email Value field of the Jenkins Configure System page.
配置的 Git 作者电子邮件(如果有的话)将用于当前工作区的 FUTURE 提交。 它是从Global Config user.email Value 全局配置 user.email 值 field of the Jenkins 詹金斯的领域Configure System 配置系统 page. 页

MERCURIAL_REVISION
Full ID of revision checked out.
已检查修订的完整 ID

MERCURIAL_REVISION_SHORT
Abbreviated ID of revision checked out.
已检查修订的缩写 ID

MERCURIAL_REVISION_NUMBER
Number of revision checked out (not portable across clones).
签出的修订数(不能跨克隆移植)

MERCURIAL_REVISION_BRANCH
Branch of revision checked out, if not checking out by branch head.
分支机构的修订检查完毕,如果没有经过分支机构头部的检查

MERCURIAL_REPOSITORY_URL
URL of repository. 存储库的 URL

SVN_REVISION
Subversion revision number that's currently checked out to the workspace, such as "12345"
当前签出到工作区的 Subversion 修订号,如“12345”

SVN_URL
Subversion URL that's currently checked out to the workspace.
当前签出到工作区的 Subversion URL

jcli 笔记

特性

易于维护的 jcli 配置文件
支持管理多个 Jenkins
插件管理(列表、搜索、安装、上传)
任务管理(搜索、构建、日志)
在浏览器中打开 Jenkins
重启 Jenkins
支持连接代理

安装

你可以从 jenkins-cli 的代码仓库中克隆 jcli(Go语言开发)。目前,我们支持三个主流的操作 系统平台: MacOS、Linux、和 Windows。

MacOS
你可以使用 brew 安装 jcli。

1
2
3
brew tap jenkins-zh/jcli
brew install jcli
Linux

在 Linux 下安装也是非常的简单。你只需要执行下面的命令即可:

1
2
curl -L https://github.com/jenkins-zh/jenkins-cli/releases/latest/download/jcli-linux-amd64.tar.gz|tar xzv
sudo mv jcli /usr/local/bin/

Windows
你可以点击下载链接到最新的版本。 然后,下载 tar 文件,把解压后的 jcli 拷贝到系统目录下。

开始使用

你安装好 jcli 后,可以通过下面的命令生成一个配置样本:

1
2
3
4
5
6
7
8
9
10
$ jcli config generate
current: yourServer
jenkins_servers:
- name: yourServer
url: http://localhost:8080/jenkins
username: admin
token: 111e3a2f0231198855dceaff96f20540a9
proxy: ""
proxyAuth: ""
# Goto 'http://localhost:8080/jenkins/me/configure', then you can generate your token.

在大多数情况下,你应该只需要修改三个字段,包括:url、username 和 token。好的,我相信你已经准备好了。 然后,就可以通过下面的命令来检查你的 Jenkins 中是否安装了 github 插件:

jcli plugin list --filter name=github

下面是详细命令说明。

command

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
jcli [Command] [Flags]        # 文档中 [command] 为必须含有命令,[flags] 为参数

Available Commands:
config 配置相关
center 管理和更新中心
completion Genereate bash completion scripts ???????
config Manage the config of jcli 配置管理jcli的配置
crumb Print crumbIssuer of Jenkins 停止job
doc Generate document for all jcl commands 生成说明文档
help Help about any command 帮助
job Print the job of your Jenkins job 管理
open Open your Jenkins with a browse 应该就是浏览器打开,没用
plugin Manage the plugins of Jenkins 管理插件
queue Manage the queue of your Jenkins 管理队列
restart Restart your Jenkins 重启
user Print the user of your Jenkins 用户管理


Global Flags:
--configFile string 备用配置文件
--debug 将输出打印到 debug.html
-j, --jenkins string 选择要控制的 jenkins 服务器
-v, --version 打印 Jenkins CLI

example:
全局可用参数:
[root@VM_89_116_centos ~]# jcli -j ex2
Jenkins CLI (jcli) manage your Jenkins
Current Jenkins is: ex2

[root@VM_89_116_centos ~]# jcli -v
Jenkins CLI (jcli) manage your Jenkins
Version: v0.0.22
Commit: eade6aa

config

1
2
3
4
5
6
7
8
9
10
命令参数说明:

# jcli config [command][Flags]

add 添加一个配置项
edit 修改一个配置项
generate 生成一个配置文件做参考
list 列出所有的配置项
remove 移除一个配置项
select 选择一个配置项
generate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
[root@VM_89_116_centos ~]# jcli config generate

生成的默认配置文件:

current: yourServer
language: ""
jenkins_servers:
- name: yourServer
url: http://localhost:8080/jenkins
username: admin
token: 111e3a2f0231198855dceaff96f20540a9
proxy: ""
proxyAuth: ""
description: ""
preHooks: []
postHooks: []
pluginSuites: []

# Language context is accept-language for HTTP header, It contains zh-CN/zh-TW/en/en-US/ja and so on
# Goto 'http://localhost:8080/jenkins/me/configure', then you can generate your token.

#语言上下文是 HTTP 头的接受语言,它包含 zh-CN/zh-TW/en/en-US/ja 等
#转到“http://localhost:8080/jenkins/me/configure”,然后可以生成令牌。


配置文件参数说明:
username:你生成密匙时所登录的用户名
proxy: 代理
proxyAuth: ""
description: ""
preHooks: []
postHooks: []
pluginSuites: []
add
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Usage:
jcli config add [flags]

Flags:
-d, --description string Description of the Jenkins
-h, --help help for add
-n, --name string Name of the Jenkins
-p, --proxy string Proxy of the Jenkins
-a, --proxyAuth string ProxyAuth of the Jenkins
-t, --token string Token of the Jenkins
--url string URL of the Jenkins
-u, --username string UserName of the Jenkins

example:
增加配置两种方式:
[root@VM_89_116_centos ~]# jcli config add -n ex1 -t 11ae42858f43b1d28335067efa4aaf6ada -u admin --url=http://localhost:8080
[root@VM_89_116_centos ~]# jcli config add -n ex2
新建 ex2 文件后,通过文件编辑器对 edit 修改文件。

在大多数情况下,只需要注意四个字段,包括:name、url、username 和 token。

[root@VM_89_116_centos ~]# jcli config edit
current: yourServer
language: ""
jenkins_servers:
- name: yourServer
url: http://localhost:8080
username: admin
token: 11d61409b3a23c5a5a340eb0423b5121b4
proxy: ""
proxyAuth: ""
description: ""
- name: ex1
url: http://localhost:8080
username: admin
token: 11ae42858f43b1d28335067efa4aaf6ada
proxy: ""
proxyAuth: ""
description: ""
preHooks: []
postHooks: []
pluginSuites: []
list
1
2
3
4
5
[root@VM_89_116_centos ~]# jcli config list

number name url description
0 *yourServer http://localhost:8080
1 ex1 http://localhost:8080
edit

[root@VM_89_116_centos ~]# jcli config edit ex1

select

[root@VM_89_116_centos ~]# jcli config select ex1

remove
1
2
3
4
5
Usage:
jcli config remove [flags]

example:
[root@VM_89_116_centos ~]# jcli config remove ex1

center

控制 jenkins 的下载更新

upgrade

Upgrade your Jenkins

[root@VM_89_116_centos ~]# jcli center upgrade

download
1
2
3
4
5
6
7
8
9
10
11
12
13
Usage:
jcli center download [flags]

Flags:
-h, --help help for download
--lts If you want to download Jenkins as LTS (default true)
-o, --output string The file of output (default "jenkins.war")
--progress If you want to show the download progress (default true)

example:
[root@VM_89_116_centos ~]# jcli center download
[root@VM_89_116_centos ~]# jcli center download -o ex4.war --progress=false
重命名为ex4.war,progress 默认为 true,显示下载进度条。
watch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

Watch your update center status

Usage:
jcli center watch [flags]

Flags:
--count int Count of watch (default 9999)
计数(默认9999)
-i, --interval int Interval of watch (default 1)
间隔(默认值1)
--util-install-complete The watch will be continue util all Jenkins plugins installation is completed
监视将继续直到所有 Jenkins 插件安装完成
--util-need-restart The watch will be continue util Jenkins needs restart
启动监视将继续直到 Jenkins 需要重新启动

watch 的参数可调,调节监控间隔时间、触发条件,通常用不到。

example:
[root@VM_89_116_centos ~]# jcli center watch
Jenkins Version: 2.190.2

completion

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

Genereate bash completion scripts

Usage:
jcli completion

Examples:
# Installing bash completion on macOS using homebrew
## If running Bash 3.2 included with macOS
brew install bash-completion
## or, if running Bash 4.1+
brew install bash-completion@2
## you may need add the completion to your completion directory
jcli completion > $(brew --prefix)/etc/bash_completion.d/jcli
## If you get trouble, please visit https://github.com/jenkins-zh/jenkins-cli/issues/83.

[root@VM_89_116_centos ~]# jcli completion > $(brew --prefix)/etc/bash_completion.d/jcli

crumb

1
2
3
4
5
6
7
8
Print crumbIssuer of Jenkins

Usage:
jcli crumb

example:
[root@VM_89_116_centos ~]# jcli crumb
Jenkins-Crumb=9775c2ca9bcbac492dcb16ca2509d5b7f89bae378553d1d761865c42ec3a924c

job

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Print the job of your Jenkins

Usage:
jcli job [flags]
jcli job [command]

Available Commands:
artifact Print the artifact list of target job: 显示出目标 job 的所有制品
build Build the job of your Jenkins: 构建job
create Create a job in your Jenkins: 创造job
delete Delete a job in your Jenkins 删除job
edit Edit the job of your Jenkins 修改一个job
history Print the history of job in your Jenkins 显示出 job 历史记录
input Input a job in your Jenkins 输入一个 job
log Print the job of your Jenkins 打印 job 日志
param Get param of the job of your Jenkins 获取 job 的参数
search Print the job of your Jenkins 查询 job
stop Stop a job build in your Jenkins 停止 job
type Print the types of job which in your Jenkins 打印出 job 的类型

Flags:
-h, --help help for job
-o, --output string Format the output (default "json")
artifact (?)
1
2
3
4
5
6
7
8
9
10
Print the artifact list of target job

Usage:
jcli job artifact <jobName> [buildID] [flags]
jcli job artifact [command]

Available Commands:
download Download the artifact of target job
Flags:
-h, --help
1
2
3
4
5
6
7
8
9
10
Usage:
jcli job artifact download <jobName> [buildID] [flags]

Download the artifact of target job

Flags:
--download-dir string The directory which artifact will be downloaded
-h, --help help for download
-i, --id string ID of the job artifact
--progress Whether show the progress (default true)
build
1
2
3
4
5
6
7
8
9
10
11
12
13
Build the job of your Jenkins

Usage:
jcli job build <jobName> [flags]

Flags:
-b, --batch Batch mode, no need confirm 批处理模式,无需确认
-h, --help help for build
--param string Params of the job 作业参数
--verbose Output the verbose 详细输出

example:
[root@VM_89_116_centos ~]# jcli job build devops_ci_cd_pipline_ex1 -b --verbose
create (?)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Create a job in your Jenkins

Usage:
jcli job create <jobName> [flags]

Flags:
--copy string Copy an exists job
-h, --help help for create
--type string Which type do you want to create

type:
Folder
GitHub Organization
Multibranch Pipeline
Freestyle project
Maven project
Multi-configuration project
Pipeline
External Job
MultiJob Project

example:
通过复制已有任务来创建新任务
[root@VM_89_116_centos ~]# jcli job create ex4 --copy devops_ci_cd_pipline_ex1
创建新任务
[root@VM_89_116_centos ~]# jcli job create ex5
edit(?)
1
2
3
4
5
6
7
8
9
Edit the job of your Jenkins 

Usage:
jcli job edit <jobName>

example:
[root@VM_89_116_centos ~]# jcli job edit devops_pipeline
2019/11/14 14:29:50 Not found resources
没用,怀疑控制浏览器打开。
delete
1
2
3
4
5
6
7
8
9
10
11
Delete a job in your Jenkins

Usage:
jcli job delete <jobName> [flags]

Flags:
-b, --batch Batch mode, no need confirm 不用询问确认是否创建
-h, --help help for delete

example:
[root@VM_89_116_centos ~]# jcli job delete ex5 -b
stop
1
2
3
4
5
6
7
8
9
10
11
12
Stop a job build in your Jenkins
似乎有 bug ,要触发两次才能生效。

Usage:
jcli job stop <jobName> <buildNumber> [flags]

Flags:
-b, --batch Batch mode, no need confirm 批处理模式,无需确认
-h, --help help for stop

example:
jcli job stop devops_ci_cd_pipline_ex1 37 -b
input(?)
1
2
3
4
5
6
7
8
9
Input a job in your Jenkins

Usage:
jcli job input <jobName> [buildID] [flags]

Flags:
--action string The action wether you want to process or abort.
活动处理或者终止
-h, --help help for input
history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Print the history of job in your Jenkins
查看历史构建状态。

Usage:
jcli job history <jobName>

example:
[root@VM_89_116_centos ~]# jcli job history devops_ci_cd_pipline_ex1
number displayname building result
0 #42 false FAILURE
1 #41 true
2 #40 true
3 #39 false SUCCESS
4 #38 false ABORTED
log
1
2
3
4
5
6
7
8
9
10
11
12
查看历史构建日志信息(控制台输出信息)。
Usage:
jcli job log <jobName> [flags]

Flags:
-h, --help help for log
-s, --history int Specific build history of log (default -1) 特殊构建历史日志
-i, --interval int Interval of watch (default 1) 查看间隔
-w, --watch Watch the job logs 查看 job 日志

example:
[root@VM_89_116_centos ~]# jcli job log devops_ci_cd_pipline_ex1
1
2
3
4
5
6
7
8
9
Usage:
jcli job search [keyword] [flags]

Flags:
--all Print all items if there's no keyword
打印所有 job
-h, --help help for search
--max int The number of limitation to print (default 10)
每次打印限制个数,默认为10
type
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Print the types of job which in your Jenkins   统计 jenkins 里面的类型

Usage:
jcli job type <jobName>

example:
[root@VM_89_116_centos ~]# jcli job type devops_ci_cd_pipline_ex1
number name type
0 Freestyle project Standalone Projects
1 Maven project Standalone Projects
2 Pipeline Standalone Projects
3 External Job Standalone Projects
4 Multi-configuration project Standalone Projects
0 MultiJob Project Uncategorized
0 Folder Nested Projects
1 GitHub Organization Nested Projects
2 Multibranch Pipeline Nested Projects
param(?)
1
2
3
4
5
6
7
8
9
Get param of the job of your Jenkins
获取 job 的参数

Usage:
jcli job param <jobName> [flags]

Flags:
-h, --help help for param
--indent Output with indent 缩进输出

open

Open your Jenkins with a browse
(用不到)

1
2
3
4
5
6
7
8
Usage:
jcli open [flags]

Flags:
-c, --config Open the configuration page of Jenkins
-h, --help help for open
-i, --interactive Interactive mode
-n, --name string Open a specific Jenkins by name

plugin

插件管理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Usage:
jcli plugin [command]

Available Commands:
check Checkout update center server 检查可更新
download Download the plugins 下载插件
install Install the plugins 安装插件
list Print all the plugins which are installed 打印已安装的插件
open Openout update center server 启动更新
search Print the plugins of your Jenkins 查找已安装的插件
trend Show the trend of the plugin 显示出插件趋势
uninstall Uninstall the plugins 卸载插件
upgrade Upgrade the specific plugin 更新特定的插件
upload Upload a plugin to your Jenkins 上传插件

Examples:

jcli plugin upgrade [plugin name] --filter stringArray Filter for the list, like: name=foo

upgrade
1
2
3
4
5
6
7
8
9
Upgrade the specific plugin

Usage:
jcli plugin upgrade [plugin name] [flags]

Flags:
--filter stringArray Filter for the list, like: name=foo 筛选
example:
[root@VM_89_116_centos ~]# jcli plugin upgrade pipeline-model-api
trend
1
2
3
4
5
6
7
8
9
Show the trend of the plugin

Usage:
jcli plugin trend <pluginName>

example:
[root@VM_89_116_centos ~]# jcli plugin trend pipeline-model-api
***************** 180628
***************** 179369
check
1
2
3
4
5
6
7
8
Checkout update center server

Usage:
jcli plugin check

example:
[root@VM_89_116_centos ~]# jcli plugin check -h
Checkout update center server
download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Download the plugins

Usage:
jcli plugin download <keyword> 关键字。。。。

example:
[root@VM_89_116_centos ~]# jcli plugin download pipeline-github
Start to collect plugin dependencies...
Ready to download plugins, total: 31.
Start to download plugin pipeline-github, version: 2.5, number: 0
Start to download plugin workflow-cps, version: 2.76, number: 1
Start to download plugin workflow-api, version: 2.37, number: 2
Start to download plugin workflow-step-api, version: 2.20, number: 3
Start to download plugin structs, version: 1.20, number: 4
Start to download plugin jdk-tool, version: 1.3, number: 5
Start to download plugin jaxb, version: 2.3.0.1, number: 6
Start to download plugin trilead-api, version: 1.0.5, number: 7
Start to download plugin scm-api, version: 2.6.3, number: 8
uninstall
1
2
3
4
5
6
7
Uninstall the plugins

Usage:
jcli plugin uninstall [pluginName]

example:
[root@VM_89_116_centos ~]# jcli plugin uninstall mapdb-api
install
1
2
3
4
5
6
7
8
9
10
Install the plugins

Usage:
jcli plugin install [pluginName] [flags]

Flags:
-h, --help help for install
--suite string Suite of plugins
example:
[root@VM_89_116_centos ~]# jcli plugin install pipeline-github
search
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@VM_89_116_centos ~]# jcli plugin search github
number name installed version installedVersion title
0 github-branch-source true 2.5.8 GitHub Branch Source Plugin
1 github true 1.29.5 GitHub plugin
2 github-api true 1.95 GitHub API Plugin
3 pipeline-github-lib true 1.0 Pipeline: GitHub Groovy Libraries
4 blueocean-github-pipeline false 1.19.0 GitHub Pipeline for Blue Ocean
5 disable-github-multibranch-status false 1.1 Disable GitHub Multibranch Status
6 github-autostatus false 3.6.0 Job and Stage monitoring
7 github-coverage-reporter false 1.8 GitHub Coverage Reporter
8 github-issues false 1.2.4 GitHub Issues
9 github-oauth false 0.33 GitHub Authentication
10 github-organization-folder false 1.6 GitHub Organization Folder
11 github-pr-comment-build false 2.1 GitHub PR Comment Build
12 github-pr-coverage-status false 2.1.1 GitHub Pull Request Coverage Status
13 github-pullrequest false 0.2.6
list
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@VM_89_116_centos ~]# jcli plugin list
number name version update
0 mercurial 2.8 false
1 pipeline-milestone-step 1.3.1 false
2 locale 1.4 false
3 teamconcert 1.3.0 false
4 mapdb-api 1.0.9.0 false
5 throttle-concurrents 2.0.1 false
6 workflow-scm-step 2.9 false
7 tfs 5.157.0 false
8 cvs 2.14 false
9 credentials-binding 1.20 false
10 matrix-auth 2.5 false
11 pam-auth 1.6 false
12 ssh 2.6.1 false
13 emailext-template 1.1 false
14 momentjs 1.1.1 false
upload:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Upload a plugin from local filesystem or remote URL to your Jenkins

Usage:
jcli plugin upload [flags]

Aliases:
upload, up

Flags:
-h, --help help for upload
-r, --remote string Remote plugin URL
--remote-jenkins string Remote Jenkins which will find from config list
--remote-password string Password of remote plugin URL
--remote-user string User of remote plugin URL
--show-progress Whether show the upload progress (default true)
--skip-posthook Whether skip the post command hook
--skip-prehook Whether skip the previous command hook

Examples:
jcli plugin upload --remote https://server/sample.hpi
jcli plugin upload sample.hpi
jcli plugin upload sample.hpi --show-progress=false

queue

队列管理

list

列出所有队列

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Usage:
jcli queue list [flags]

Flags:
-h, --help help for list
-o, --output string Format the output (default "json")

example:
[root@VM_89_116_centos ~]# jcli queue list

{
"Items": [
{
"Blocked": false,
"Buildable": true,
"ID": 122,
"Params": "",
"Pending": false,
"Stuck": false,
"URL": "queue/item/122/",
"Why": "等待下一个可用的执行器",
"BuildableStartMilliseconds": 1573714706814,
"InQueueSince": 1573714706758,
"Actions": []
},
{
"Blocked": false,
"Buildable": true,
"ID": 120,
"Params": "",
"Pending": false,
"Stuck": false,
"URL": "queue/item/120/",
"Why": "等待下一个可用的执行器",
"BuildableStartMilliseconds": 1573714673447,
"InQueueSince": 1573714673446,
"Actions": []
},
{
"Blocked": false,
"Buildable": true,
"ID": 118,
"Params": "",
"Pending": false,
"Stuck": false,
"URL": "queue/item/118/",
"Why": "等待下一个可用的执行器",
"BuildableStartMilliseconds": 1573714663446,
"InQueueSince": 1573714663418,
"Actions": []
}
]
}

cancel

取消队列

1
2
3
4
5
6
7
Usage:
jcli queue cancel <id> [flags]
Flags:
-h, --help

example:
[root@VM_89_116_centos ~]# jcli queue cancel 118

restart

重启

1
2
3
4
5
Usage:
jcli restart [flags]

Flags:
-b, --batch Batch mode, no need confirm

user

用户管理

1
2
3
4
5
6
7
8
9
10
11
12
13
Usage:
jcli user [flags]
jcli user [command]

Available Commands:
create Create a user for your Jenkins
delete Delete a user for your Jenkins
edit Edit the user of your Jenkins
token Token the user of your Jenkins

Flags:
-h, --help help for user
-o, --output string Format the output (default "json")

create
1
2
3
4
5
jcli user create <username> [password] 

example:
[root@VM_89_116_centos ~]# jcli user create admin1 admin1
create user success. Password is: admin1
delete
1
2
3
4
5
6
7
8
9
Usage:
jcli user delete <username> [flags]

Flags:
-b, --batch Batch mode, no need confirm 批处理模式,无需确认

example:
[root@VM_89_116_centos ~]# jcli user delete admin1
? Are you sure to delete user admin1 ? Yes
edit
1
2
3
4
5
6
7
Usage:
jcli user edit [flags]

Flags:
-d, --desc Edit the description

仅仅修改描述,不支持修改密码权等高级功能
token
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Usage:
jcli user token -g [flags]

Flags:
-g, --generate Generate the token
-n, --name string Name of the token

example:
[root@VM_89_116_centos ~]# jcli user token -g

{
"Status": "ok",
"Data": {
"TokenName": "jcli-Mouseflash",
"TokenUUID": "d7de368b-bb54-44a4-99ef-db1674a07e42",
"TokenValue": "1109aceacc74236930f5ef2d6372d2704e"
}
}

[root@VM_89_116_centos ~]# jcli user token -g -n 测试

{
"Status": "ok",
"Data": {
"TokenName": "测试",
"TokenUUID": "8a642d49-78ee-448a-8abc-59d29b5f4a68",
"TokenValue": "114229e08012d8b29f15d98986ef0f8f09"
}
}

问题总结

1、jcli job build devops_ci_cd_pipline_ex1 -b
不支持连续,需要等待上一条 build 完全进入 build 才会 启动下一条 build

2、不支持查看正在构建的任务清单。

3、不支持修改构建任务的配置。

4、不支持查看已经存在的用户列表

喜欢这篇文章?打赏一下作者吧!

欢迎关注我的其它发布渠道