1、要在 Linux 操作系统上安装 jcli
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/
在用户根目录下,增加 jcli 的配置文件:
jcli config gen -i=false > ~/.jenkins-cli.yaml
修改配置文件中的url,username,token 的值
[root@sre-test-01 jcli]# cat /root/.jenkins-cli.yaml
current: yourServer
jenkins_servers:
- name: yourServerurl: http://xxxx.xxx.xxx.com/username: testtoken: xxxxxxxxxxxxxxxxxxxinsecureSkipVerify: true
mirrors:
- name: defaulturl: http://mirrors.jenkins.io/
- name: tsinghuaurl: https://mirrors.tuna.tsinghua.edu.cn/jenkins/
- name: huaweiurl: https://mirrors.huaweicloud.com/jenkins/
- name: tencenturl: https://mirrors.cloud.tencent.com/jenkins/
# 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.
可以发现,上面的配置文件中可以配置多个 Jenkins。下面的命令可以让你看到当前所选择的地址信息:
jcli config
Jenkins 有丰富的插件生态,下面我们演示如何对插件进行搜索、安装、删除等操作。
首先,让我们先检查更新:
jcli plugin check
然后,可以根据关键字搜索我们所需要的插件:
jcli plugin search restful
安装:
jcli plugin install pipeline-restful-api
查看安装进度:
jcli center watch
所有的插件安装完成后,重启后就可以看到了:
jcli restart -b
等 Jenkins 重启完成后,可以看到所有安装好的插件列表:
jcli plugin list
执行任务
jcli job build hello-pipeline -b
查看任务执行日志
jcli job log hello-pipeline -w