环境
系统:Ubuntu22.04
软件:Jenkins最新版,目前最新稳定版本为2.401,最新版为:2.418
安装
1、接受Jenkins的密钥
sudo curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \
/usr/share/keyrings/jenkins-keyring.asc > /dev/null
2、添加一个Jenkins apt存储库(相对于添加一个源)
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
3、安装
# 更新
sudo apt update
# 查看可安装的版本
sudo apt-cache madison jenkins |head
# 此处安装的Jenkins 2.401.3
sudo apt-get install fontconfig openjdk-11-jre
sudo apt install jenkins=2.401.3
# 如果2.401.3是Jenkins最新稳定版,可执行下面命令
sudo apt install jenkins
在安装过程中可能会出现以下报错:
# 出现以上报错后执行下面操作:
sudo mv /var/lib/dpkg/info/ /var/lib/dpkg/info_old/
sudo mkdir /var/lib/dpkg/info/
sudo apt-get update
# 再进行安装操作
sudo apt install jenkins=2.401.3 -y
安装完成:
查看Jenkins状态:sudo systemctl status jenkins
查看日志:sudo journalctl -u jenkins.service
原因:因为安装Gitlab,8080端口被占用,所以需要修改
解决方法如下:
# 修改端口操作
sudo vim /lib/systemd/system/jenkins.service
Environment="JENKINS_PORT=5000"
# 重启Jenkins
sudo systemctl daemon-reload
sudo systemctl restart jenkins.service
# 再次查看状态则正常
sudo systemctl status jenkins.service
4、验证
查看端口正常启动
登录前台页面:http://ip:port
安装之后修改admin密码
修改之后点击保存即可
Jenkins配置https
创建SSL密钥库
sudo mkdir /etc/jenkins
sudo keytool -genkey -keyalg RSA -alias jenkins -keystore /etc/jenkins/jenkins.jks -storepass 123456 -keypass 123456
修改Jenkins配置
sudo vim /lib/systemd/system/jenkins.service
# 修改如下内容:
User=root
Environment="JENKINS_PORT=-1"
Environment="JENKINS_HTTPS_PORT=443"
Environment="JENKINS_HTTPS_LISTEN_ADDRESS=0.0.0.0"
# Path to the keystore in JKS format (as created by the JDK's keytool).
Environment="JENKINS_HTTPS_KEYSTORE=/etc/jenkins/jenkins.jks"
# Password to access the keystore defined in JENKINS_HTTPS_KEYSTORE.
Environment="JENKINS_HTTPS_KEYSTORE_PASSWORD=123456"
#修改完成后,重新加载并重启
sudo systemctl daemon-reload
sudo systemctl restart jenkins.service
重启后查看前台页面:已经是https模式了