Jenkins_用户权限&凭证管理
2021-04-15 本文已影响0人
慕知
一,Jenkins用户权限
可以利用Role-based Authorization Strategy 插件来管理Jenkins用户权限
![](https://img.haomeiwen.com/i23958203/a99db9f310911c11.png)
![](https://img.haomeiwen.com/i23958203/21d76fc9e3cc75ea.png)
![](https://img.haomeiwen.com/i23958203/da2b70d8f78a4f2f.png)
1,创建用户
![](https://img.haomeiwen.com/i23958203/3abf06284c162225.png)
2,创建权限组
![](https://img.haomeiwen.com/i23958203/632031b899783e49.png)
![](https://img.haomeiwen.com/i23958203/91db9b399c64033b.png)
3,分配角色
![](https://img.haomeiwen.com/i23958203/2d095d6f0dc15f44.png)
4,创建项目
![](https://img.haomeiwen.com/i23958203/1067b6ac81f88bf9.png)
![](https://img.haomeiwen.com/i23958203/8127c09246a03abc.png)
5,登录egon用户查看
![](https://img.haomeiwen.com/i23958203/f2c284f227e1f814.png)
6,支持正则
![](https://img.haomeiwen.com/i23958203/94b391c8b61d2616.png)
![](https://img.haomeiwen.com/i23958203/1a834c510e2f1c78.png)
![](https://img.haomeiwen.com/i23958203/851beb304f6fde6f.png)
![](https://img.haomeiwen.com/i23958203/90b472b9fd1b66b3.png)
二,凭证管理
要在Jenkins使用凭证管理功能,需要安装Credentials Binding插件。
系统管理--->
![](https://img.haomeiwen.com/i23958203/8e0968bd3fc580b0.png)
方式一:账号和密码
![](https://img.haomeiwen.com/i23958203/3876fdb6a88e1d50.png)
![](https://img.haomeiwen.com/i23958203/0bc4fb705ec8750a.png)
![](https://img.haomeiwen.com/i23958203/ed246fd639114a08.png)
![](https://img.haomeiwen.com/i23958203/77ffe9802b047003.png)
![](https://img.haomeiwen.com/i23958203/52298e2bed79df43.png)
![](https://img.haomeiwen.com/i23958203/dfb58963f08f39c2.png)
# 查看jenkins服务器上已经拉取了gitlab的代码
[root@\ jenkins~]# cd /var/lib/jenkins/workspace/shanghai_boy
[root@\ jenkins/var/lib/jenkins/workspace/shanghai_boy]# ll
total 8
-rw-r--r--. 1 jenkins jenkins 4 Apr 15 14:11 a.txt
-rw-r--r--. 1 jenkins jenkins 12 Apr 15 14:11 README.md
方式二:
SSH Username with private key:即使用私钥的SSH 用户名。这是一个SSH 秘钥对。公钥配置在GitHub上面,这里添加私钥。
![](https://img.haomeiwen.com/i23958203/2b1a1404bb78b022.png)
![](https://img.haomeiwen.com/i23958203/251202184f57a55e.png)
![](https://img.haomeiwen.com/i23958203/045d03e576e7bdc1.png)
![](https://img.haomeiwen.com/i23958203/ae75f3b2de5be8d3.png)
方式三
![](https://img.haomeiwen.com/i23958203/277d3443f0beb0d2.png)
![](https://img.haomeiwen.com/i23958203/729ca5573239ab6e.png)
# 公钥发送到指定服务器上
[root@\ jenkins~]# ssh-copy-id -i .ssh/id_rsa.pub root@192.168.15.108
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: ".ssh/id_rsa.pub"
The authenticity of host '192.168.15.108 (192.168.15.108)' can't be established.
ECDSA key fingerprint is SHA256:PEnseRsQ3H01Fz7upthyVuJfTYF/AKSpERCAxx1052M.
ECDSA key fingerprint is MD5:e7:ba:23:9f:6c:2b:77:12:7b:68:a8:5f:bc:eb:c0:01.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.15.108's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.15.108'"
and check to make sure that only the key(s) you wanted were added.
#测试登录到web02
[root@\ jenkins~]# ssh 'root@192.168.15.108'
Last login: Thu Apr 15 08:46:34 2021 from 192.168.15.1
[root@\ web02~]# exit
logout
Connection to 192.168.15.108 closed.
第三种方式,可以不断的增加server信息,直接构建部署到该服务器上
三,简单构建流程:
![](https://img.haomeiwen.com/i23958203/c4f66d75d132b375.png)
![](https://img.haomeiwen.com/i23958203/ca915f1804dbd8c9.png)
验证:
[root@\ web02~]# cd /usr/share/nginx/html/
[root@\ web02/usr/share/nginx/html]# ll
total 0
drwxr-xr-x. 2 root root 67 Apr 15 17:38 bbb
[root@\ web02/usr/share/nginx/html]# cd bbb/
# 远程仓库内容
[root@\ web02/usr/share/nginx/html/bbb]# ll
total 16
-rw-r--r--. 1 root root 4 Apr 15 17:38 a.txt
-rw-r--r--. 1 root root 47 Apr 15 17:38 egon.txt
-rw-r--r--. 1 root root 12 Apr 15 17:38 README.md
-rw-r--r--. 1 root root 47 Apr 15 17:38 tet.txt
# 构建时执行的shell变量
[root@\ web02/usr/share/nginx/html/bbb]# cat egon.txt
http://192.168.15.90:8080/job/shanghai_boy/11/
[root@\ web02/usr/share/nginx/html/bbb]# cd
# 创建的目录
[root@\ web02~]# ll /egon/
total 0
![](https://img.haomeiwen.com/i23958203/4e2a559662e58e44.png)
![](https://img.haomeiwen.com/i23958203/1f8dde358b2c2ee2.png)