第十四章 jenkins的详细介绍

一、jenkins的安装

1.安装java

[root@jenkins ~]# yum install java-1.8.0-openjdk* -y

2.安装jenkins

1)第一种方式

# 官方推荐
# 下载镜像源
[root@jenkins ~]# wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo

# 安装认证Key
[root@jenkins ~]# rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key

# 安装JenKins
[root@jenkins ~]# yum install jenkins -y

2)第二种方式

# 下载安装包
[root@jenkins ~]# wget https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/jenkins-2.249.1-1.1.noarch.rpm
或
[root@jenkins ~]# rz jenkins-2.249.1-1.1.noarch.rpm

#安装jenkins
[root@jenkins ~]# yum localinstall jenkins-2.249.1-1.1.noarch.rpm

3.启动jenkins并设置开机自启

[root@jenkins ~]# systemctl enable jenkins
[root@jenkins ~]# systemctl start jenkins

4.网页登录

10.0.0.62:8080

image

5.获取初始密码

[root@jenkins ~]# cat /var/lib/jenkins/secrets/initialAdminPassword

二、jenkins插件管理

1.安装插件

#1.上传插件包
[root@jenkins ~]# cd /var/lib/jenkins/plugins
[root@jenkins /var/lib/jenkins/plugins]# rz plugins.tar.gz

#2.解压插件包
[root@jenkins /var/lib/jenkins/plugins]# tar xf plugins.tar.gz

#3.查看安装插件
登录页面-->系统管理-->插件管理

2.更换插件源

# 切换至配置文件目录
[root@jenkins /var/lib/jenkins/plugins]# cd /var/lib/jenkins/updates

# 换源
[root@jenkins /var/lib/jenkins/updates]# sed -i 's/http:\/\/updates.jenkinsci.org\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g' default.json
或
[root@jenkins /var/lib/jenkins/updates]# sed -i 's/http:\/\/updates.jenkinsci.org\/download/https:\/\/mirrors.aliyun.com\/jenkins/g' default.json

[root@jenkins /var/lib/jenkins/updates]# sed -i 's/http:\/\/www.google.com/https:\/\/www.baidu.com/g' default.json

3.升级站点

# 插件管理点击高级,把站点升级改为国内插件下载地址:
https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
或
https://mirrors.aliyun.com/jenkins/updates/update-center.json

image

4.重启服务

[root@jenkins ~]# systemctl restart jenkins

三、jenkins用户权限

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

1.开启权限全局安全配置

image

image

2.创建角色

image

Global roles(全局角色):管理员等高级用户可以创建基于全局的角色 
Item roles(项目角色): 针对某个或者某些项目的角色 
Node roles(节点角色):节点相关的权限

image

Base: 设置成所有的用户都有查看的权限
Alvin: 设置以alvin开头的项目有超管权限
Oldboy:设置以oldboy开头的项目有超管权限

image

3.创建用户

image

image

image

4.分配角色

image

image

image

image

四、jenkins凭证管理

1.jenkins凭证管理简介

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

image

image

image

1.	Username with password:用户名和密码
2.	SSH Username with private key: 使用SSH用户和密钥
3.	Secret file:需要保密的文本文件,使用时Jenkins会将文件复制到一个临时目录中,再将文件路径 设置到一个变量中,等构建结束后,所复制的Secret file就会被删除。
4.	Secret text:需要保存的一个加密的文本串,如钉钉机器人或Github的api token Certificate:通过上传证书文件的方式
5.	X.509:证书,一般使用第三方云服务时使用。
6.	Certificate:docker私有仓库密码存储类型。

2.jenkins凭证密码登录

Username with password:用户名和密码

image

image

image

image

image

image

3.jenkins凭证密钥登录

#1.生成公钥对
[root@jenkins /var/lib/jenkins/updates]# ssh-keygen -t rsa

#2.查看公钥
[root@jenkins /var/lib/jenkins/updates]# cat /root/.ssh/id_rsa.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDFSuphRl/Tl2rcEMaXb5Gn05l5KUyQJcqE8hYiGiW9oPr1ZeKZQgYAksiOQ0fVwgVZZ7N+rTDI3qz9+OztO8GZCLjLuDy8LMK0YfNCsoN7l6oz9dwfN3hkcbtf57lwla5BNCVL+mYbnQhAXFNXYRUkll7GbZyp8e44hyrPiBUsTwy9FnC3XHl+lrf1QXOs9pDA3fJRF0mwSeqot+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NM7whO9ThihxjuEWfdZlNHMsHEexsLywrTmsCgYEA08Yc
ffTjG3GII+23o9cPqv2C3tykWdJDKjXwEY/PxljB2CCTElxb7a4BTqzSp2WDIKJE
P8+M4U0jYLq808zb5Rx3oTZKVGpKOcDIarFX9iq136uQyA4euyNaRq+zGsOdMdbH
KjwZG3ZavqYleCCFBnOF43rJsHhHxS4NG2+S+UUCgYEAzilLZsZa48r/QNjtJ5Qy
2kB02cfkjDqMNHIM/CmLYgBGr7ESEuGVSpFgLEQ5u6RnX5b2pqrxit6mvHy0GR1g
9Kojeha1hLBCX9Gxqmj+VPl2Mnqp13kiOy1Q+61JAVa6N9lWQoqllu8tm1bukEDy
QryMl0+pxRYMSoYhDrYTyXkCgYEAre9CSYWP3mNyAKhnMw8ZFEShb2/jIM7cUVf5
tELc0TjnBR9EDEmFS4KmGjtBzTFH8M61pX9PY2Da1MCrBH52gQfPjb4scIbYLfUT
5uV/rHTJ6kpcYKOQQ/22UOZQAYR2oI+aBytTJ8YepAWMMszq1TCe4AZijylLMT0w
kL8kBM0CgYAcHbegHCFXhiH47n1ClzjP03yBtD1B9ub2u0vdNch2gMywzMZgdSmv
xXL0ZeMbagrePMvVALWrhnA1xQTQgQ99NXvFUYQhw61YPX+JWhXj3MQUiOTqLU9l
6kljNv4aPSN1uCX8YojFSW4Spdc30qHhnJN6C2e221elLXyRMs9gyw==
-----END RSA PRIVATE KEY-----

#4.gitlab配置公钥

image

#5.jenkins配置私钥

image

image

image

image

4.jenkins构建变量

Jenkins变量也被称为参数化构建。

image

image

posted @ 2022-01-25 19:05  年少纵马且长歌  阅读(175)  评论(0编辑  收藏  举报