Jenkins 简介

Jenkins是开源CI&CD软件领导者, 提供超过1000个插件来支持构建、部署、自动化, 满足任何项目的需要。

在这里插入图片描述

官方网站:https://www.jenkins.io/

项目地址:https://github.com/jenkinsci/jenkins

Ubuntu安装 jenkins

OS版本: ubuntu 22.04 LTS

官方文档:https://pkg.jenkins.io/debian/

配置Jenkins 的 Debian 软件包存储库,用于自动安装和升级。要使用此存储库,请首先将密钥添加到您的系统中:

curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee \
/usr/share/keyrings/jenkins-keyring.asc > /dev/null

然后添加 Jenkins apt 存储库条目:

echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
https://pkg.jenkins.io/debian binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null

需要显式安装受支持的 Java 运行时环境 (JRE),无论是您的发行版(如上所述)还是其他 Java 供应商(例如Adoptium)。

sudo apt-get update
sudo apt-get install -y fontconfig openjdk-17-jre

更新本地包索引,然后最后安装 Jenkins:

sudo apt-get install -y jenkins

查看jenkins运行状态

systemctl status jenkins

注意:当我们在安装完 **jenkins** 的时候,别着急登录web进行初始化操作,先按照以下流程设置下国内update-center源。

配置国内update-center

原文地址: https://lework.github.io/2020/03/05/jenkins-update-center/

项目地址:https://github.com/lework/jenkins-update-center

国内已经有几家站点都同步了 jenkins 仓库和插件仓库,当你设置了清华大学的 update-center.json 时,在满怀欣喜的等待飙升的下载速度,得到的确实一动不动的进度条,那是因为国内镜像源是原封不动的同步 jenkins仓库的,其 update-center.json 里的插件下载地址还是 jenkins 的地址,当然加速不了。需要把这个文件里的下载路径更改为国内镜像源地址,才能享受飙升的下载速度。

为此,这里针对国内的镜像站点一一生成了 update-center.json 下面就介绍如何使用!

测试速度

在使用国内镜像站点的时候,不妨先测试下哪个站点下载速度最快的。镜像站点清单如下

站点名称站点地址
tsinghuahttps://mirrors.tuna.tsinghua.edu.cn/jenkins/
ustchttps://mirrors.ustc.edu.cn/jenkins/
huaweihttps://mirrors.huaweicloud.com/jenkins/
aliyunhttps://mirrors.aliyun.com/jenkins/
tencenthttps://mirrors.cloud.tencent.com/jenkins/
bithttps://mirror.bit.edu.cn/jenkins/

使用脚本进行测速

# curl -sSL https://cdn.jsdelivr.net/gh/lework/jenkins-update-center/speed-test.sh | bash


Jenkins mirror update center speed test

[Mirror Site]
ustc          :  https://mirrors.ustc.edu.cn/jenkins/
aliyun        :  https://mirrors.aliyun.com/jenkins/
bit           :  https://mirrors.bit.edu.cn/jenkins/
huawei        :  https://mirrors.huaweicloud.com/jenkins/
tencent       :  https://mirrors.cloud.tencent.com/jenkins/
tsinghua      :  https://mirrors.tuna.tsinghua.edu.cn/jenkins/

[Test]
Test File        : updates/current/plugin-versions.json

Site Name     IPv4 address        File Size     Download Time       Download Speed
ustc                              16M           0.3s                51.4MB/s      
aliyun                            16M           0.7s                22.6MB/s      
bit                               16M           0.4s                35.6MB/s      
huawei                            16M           0.5s                30.2MB/s      
tencent                           16M           3.4s                4.63MB/s      
tsinghua                          16M           0.5s                34.5MB/s       

使用国内镜像

上传自定义的 ca 证书

[ ! -d /var/lib/jenkins/update-center-rootCAs ] && mkdir /var/lib/jenkins/update-center-rootCAs
wget https://cdn.jsdelivr.net/gh/lework/jenkins-update-center/rootCA/update-center.crt -O /var/lib/jenkins/update-center-rootCAs/update-center.crt
chown jenkins.jenkins -R /var/lib/jenkins/update-center-rootCAs

注意: 如果在上述操作后,还是出现证书校验不通过的错误信息,可以试试下面的操作。

# centos/redhat
sudo wget https://cdn.jsdelivr.net/gh/lework/jenkins-update-center/rootCA/update-center.crt -O /etc/pki/catrust/source/anchors/update-center.crt
sudo update-ca-trust extract
sudo update-ca-trust enable
    
# debian/ubuntu
sudo https://cdn.jsdelivr.net/gh/lework/jenkins-update-center/rootCA/update-center.crt -O /usr/share/ca-certificates/update-center.crt
sudo update-ca-certificates

更改插件更新中心的 url 地址,这里在命令行终端里进行更改

sed -i 's#https://updates.jenkins.io/update-center.json#https://cdn.jsdelivr.net/gh/lework/jenkins-update-center/updates/huawei/update-center.json#' /var/lib/jenkins/hudson.model.UpdateCenter.xml
[ -f /var/lib/jenkins/updates/default.json ] && rm -fv /var/lib/jenkins/updates/default.json
systemctl restart jenkins

当然也可以通过web 来更改:Go to JenkinsManage JenkinsManage PluginsAdvanced → Update Site and submit URL to your https://cdn.jsdelivr.net/gh/lework/jenkins-update-center/updates/huawei/update-center.json

然后再去 web 页面初始化你的 jenkins,享受速度飙升的快感吧。

update-center.json

文件会在每天utc时间1点钟更新

SiteSourceCDN
tencenthttps://raw.githubusercontent.com/lework/jenkins-update-center/master/updates/tencent/update-center.jsonhttps://cdn.jsdelivr.net/gh/lework/jenkins-update-center/updates/tencent/update-center.json
huaweihttps://raw.githubusercontent.com/lework/jenkins-update-center/master/updates/huawei/update-center.jsonhttps://cdn.jsdelivr.net/gh/lework/jenkins-update-center/updates/huawei/update-center.json
tsinghuahttps://raw.githubusercontent.com/lework/jenkins-update-center/master/updates/tsinghua/update-center.jsonhttps://cdn.jsdelivr.net/gh/lework/jenkins-update-center/updates/tsinghua/update-center.json
ustchttps://raw.githubusercontent.com/lework/jenkins-update-center/master/updates/ustc/update-center.jsonhttps://cdn.jsdelivr.net/gh/lework/jenkins-update-center/updates/ustc/update-center.json
bithttps://raw.githubusercontent.com/lework/jenkins-update-center/master/updates/bit/update-center.jsonhttps://cdn.jsdelivr.net/gh/lework/jenkins-update-center/updates/bit/update-center.json

初始化jenkins

登录jenkins管理界面

http://192.168.72.51:8080

初始化界面如下:
在这里插入图片描述

获取默认用户admin的密码,并填写

root@ubuntu:~# cat /var/lib/jenkins/secrets/initialAdminPassword
0c18a09249b44a20881ba11142b5bba7

安装推荐的插件

在这里插入图片描述
忽略安装失败的插件,点击继续
在这里插入图片描述

创建管理员用户
在这里插入图片描述
配置Jenkins URL地址
在这里插入图片描述
Jenkins安装完成
在这里插入图片描述
进入管理界面
在这里插入图片描述

参考文章: https://lework.github.io/2020/03/05/jenkins-update-center/

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐