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