1、环境准备:准备安装好docker的服务器一台
2、在服务器上创建一个目录用于安装Jenkins
powershell
mkdir jenkins
3、下载好要挂载的:maven、jkd;并将下载好的tar.gz包上传至服务器待安装目录中并解压
powershell
tar -xzvf tar -xzvf apache-maven-3.9.6-bin.tar.gz
tar -xzvf graalvm-jdk-21_linux-x64_bin.tar.gz
4、修改解压后maven中的setting配置文件
主要修改仓库存储路径和镜像仓库
xml
<localRepository>/root/jenkins/repo</localRepository>
<!-- 配置阿里云镜像地址 -->
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
5、配置maven和jdk的PATH挂载文件,git用系统默认的就行,不需要额外配置
powershell
mkdir -p ~/jenkins/conf
vi profile
profile内容
powershell
export MAVEN_HOME=/usr/local/maven/apache-maven-3.9.6
export PATH=$MAVEN_HOME/bin:$PATH
export JAVA_HOME=/usr/local/java/graalvm-jdk-21.0.2+13.1
export PATH=$JAVA_HOME/bin:$PATH
6、配置jenkins的docker-compose.yml文件
yaml
version: '3.9'
services:
jenkins:
image: jenkins/jenkins:2.440.2
container_name: jenkins
user: root
restart: always
deploy:
resources:
limits:
cpus: '1.00'
memory: 1G
reservations:
cpus: '0.10'
memory: 256M
ports:
- "8080:8080"
- "50000:50000"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /usr/bin/docker:/usr/bin/docker
- ./data:/var/jenkins_home
- ./apache-maven-3.9.6:/usr/local/maven/apache-maven-3.9.6
- ./graalvm-jdk-21.0.2+13.1:/usr/local/java/graalvm-jdk-21.0.2+13.1
- ./conf/profile:/root/.bashrc
environment:
- TZ=Asia/Shanghai
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/login"]
interval: 30s
timeout: 10s
retries: 8
start_period: 60s
7、启动好后访问,跟随引导安装推荐插件和创建账户
8、配置环境变量,只需配置:系统管理--全局属性--环境变量:PATH
path获取方法:进入Jenkins的docker中进行获取
powershell
docker exec -it jenkins bash
echo $PATH
PATH变量
powershell
/usr/local/java/graalvm-jdk-21.0.2+13.1/bin:/usr/local/maven/apache-maven-3.9.6/bin:/opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
配置完成后截图:
9、访问403异常错误排查:
MESSAGE: No valid crumb was included in the request
处理办法:
将【启用代理兼容】勾上
10、新建一个流水线任务并配置pipeline脚本:
java
pipeline {
agent any
stages {
stage('开始') {
// 开始
steps {
echo "开始"
}
}
stage('环境检测') {
steps {
// 构建环境检测
sh '''
cat /proc/version
free -m
df -h
docker -v
git -v
mvn -v
java -version
'''
echo 'Hello jenkins'
}
}
stage('你好 jenkins') {
// 结束
steps {
echo "结束"
}
}
}
}
配置截图:
11、保存后点击:立即构建