Jenkins_用户权限&凭证管理

2021-04-15  本文已影响0人  慕知

一,Jenkins用户权限

可以利用Role-based Authorization Strategy 插件来管理Jenkins用户权限

系统设置--> 全局安全配置 开启权限全局安全配置 多出图上标识

1,创建用户

系统管理--> 管理用户

2,创建权限组

image.png 创建项目角色

3,分配角色

image.png

4,创建项目

创建项目 项目查看

5,登录egon用户查看

登录egon用户即可看见shanghai_boy项目

6,支持正则

创建xiaohua用户 创建权限组 给与xiaohua以xiaohua_group的权限 登录xioahua用户可以匹配两个shanghai开头的项目

二,凭证管理

要在Jenkins使用凭证管理功能,需要安装Credentials Binding插件。

系统管理--->
image.png

方式一:账号和密码

方式一 配置项目shanghai_boy 配置如图 image.png 接上图 image.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上面,这里添加私钥。

image.png 获取公私钥 image.png gitlab填入公钥

方式三

image.png image.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信息,直接构建部署到该服务器上

三,简单构建流程:

image.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

image.png 构建的时候,会有标签选择
上一篇 下一篇

猜你喜欢

热点阅读