跳到主要内容

[toc]

jenkins安装

jenkins中文官网

jenkins官网

jenkins github

标准安装

安装jdk

jenkins版本与jdk版本兼容说明 官方文档

Supported Java versionsLong term support (LTS) releaseWeekly release
Java 17 or Java 212.479.1 (October 2024)2.463 (June 2024)
Java 11, Java 17, or Java 212.426.1 (November 2023)2.419 (August 2023)
Java 11 or Java 172.361.1 (September 2022)2.357 (June 2022)
Java 8, Java 11, or Java 172.346.1 (June 2022)2.340 (March 2022)
Java 8 or Java 112.164.1 (March 2019)2.164 (February 2019)
Java 82.60.1 (June 2017)2.54 (April 2017)
Java 71.625.1 (October 2015)1.612 (May 2015)

openjdk安装可参考 官方文档

查看可安装版本

dnf list available | grep openjdk

安装

dnf -y install java-21-openjdk

安装jenkins

rpm包安装

jenkins lts版 rpm包官方下载地址

下载安装包

wget https://get.jenkins.io/redhat-stable/jenkins-2.516.3-1.1.noarch.rpm

安装

dnf localinstall jenkins-2.516.3-1.1.noarch.rpm

yum源安装

# 下载源
wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo

# 导入key
rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key

# 安装jenkins
yum -y install jenkins

查看jenkins相关配置

说明

高版本的jenkins配置文件目录在 /var/lib/jenkins

$ egrep -v '^$|#' /usr/lib/systemd/system/jenkins.service
[Unit]
Description=Jenkins Continuous Integration Server
Requires=network.target
After=network.target
StartLimitBurst=5
StartLimitIntervalSec=5m
[Service]
Type=notify
NotifyAccess=main
ExecStart=/usr/bin/jenkins
Restart=on-failure
SuccessExitStatus=143
User=jenkins
Group=jenkins
Environment="JENKINS_HOME=/var/lib/jenkins"
WorkingDirectory=/var/lib/jenkins
Environment="JENKINS_WEBROOT=%C/jenkins/war"
Environment="JAVA_OPTS=-Djava.awt.headless=true"
Environment="JENKINS_PORT=8080"
[Install]
WantedBy=multi-user.target

启动jenkins

systemctl enable jenkins && systemctl start jenkins

访问jenkins

jenkins刚启动比较慢,等待启动完成

iShot_2025-09-28_15.14.46

/var/lib/jenkins/secrets/initialAdminPassword 文件按中获取密码

iShot_2025-09-28_15.16.34

配置jenkins

安装插件

iShot_2025-09-28_15.19.32

等待安装完成

iShot_2025-09-28_15.20.33

创建管理员用户(可选)

也可以使用admin用户继续

iShot_2025-09-28_15.24.21

确认jenkins访问地址

iShot_2025-09-28_15.26.30

开始使用

iShot_2025-09-28_15.30.26

jenkins登陆首界面

iShot_2025-09-28_15.33.13

docker安装

jenkins dockerhub

jenkins docker github

jenkins docker安装官方文档

docker run \
-d \
-h jenkins \
--name jenkins \
--restart=on-failure \
-p 8080:8080 \
-p 50000:50000 \
-v jenkins_home:/var/jenkins_home \
jenkins/jenkins:2.516.3-lts-jdk21

登陆jenkins后如果提示jenkins反向代理配置错误,参考 官方提供的nginx配置 即可

upstream jenkins {
keepalive 32; # keepalive connections
server 127.0.0.1:8080; # jenkins ip and port
}

# Required for Jenkins websocket agents
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}

server {
listen 80; # Listen on port 80 for IPv4 requests

server_name jenkins.example.com; # replace 'jenkins.example.com' with your server domain name

# this is the jenkins web root directory
# (mentioned in the output of "systemctl cat jenkins")
root /var/run/jenkins/war/;

access_log /var/log/nginx/jenkins.access.log;
error_log /var/log/nginx/jenkins.error.log;

# pass through headers from Jenkins that Nginx considers invalid
ignore_invalid_headers off;

location ~ "^\/static\/[0-9a-fA-F]{8}\/(.*)$" {
# rewrite all static files into requests to the root
# E.g /static/12345678/css/something.css will become /css/something.css
rewrite "^\/static\/[0-9a-fA-F]{8}\/(.*)" /$1 last;
}

location /userContent {
# have nginx handle all the static requests to userContent folder
# note : This is the $JENKINS_HOME dir
root /var/lib/jenkins/;
if (!-f $request_filename){
# this file does not exist, might be a directory or a /**view** url
rewrite (.*) /$1 last;
break;
}
sendfile on;
}

location / {
sendfile off;
proxy_pass http://jenkins;
proxy_redirect default;
proxy_http_version 1.1;

# Required for Jenkins websocket agents
proxy_set_header Connection $connection_upgrade;
proxy_set_header Upgrade $http_upgrade;

proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_max_temp_file_size 0;

#this is the maximum upload size
client_max_body_size 10m;
client_body_buffer_size 128k;

proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_request_buffering off; # Required for HTTP CLI commands
}
}
Bottom GIF
Top GIF