本次安装版本:2.4+
jenkins详细安装教程
https://blog.csdn.net/Tm598035415/article/details/142916486
1、安装git环境
yum一键安装
sudo yum install git
验证安装,出现版本号,即安装成功
git --version
2、安装mavne环境
2.1 下载依赖
mkdir /home/jenkins
cd /home/jenkins
yum install zip
yum install unzip
wget https://dlcdn.apache.org/maven/maven-3/3.9.9/binaries/apache-maven-3.9.9-bin.zip
2.2、解压、赋权
uzip -r apache-maven-3.9.9-bin.zip
chmod -R 777 ./apache-maven-3.9.9
2.2、配置环境变量
编辑环境变量文件
vim /etc/profile
追加以下内容
export M2_HOME=/home/jenkins/apache-maven-3.9.9
export PATH=${M2_HOME}/bin:${PATH}
让环境变量文件立刻生效
source /etc/profile
2.3、验证安装
mvn -v
3、jenkins-插件下载
3.1、进入jenkins–>系统管理
3.2、进入系统管理–>插件管理
3.3、下载两个插件(如果之前下载了,这里是搜索不到的,请直接去3.4)
// 在搜索栏,下载以下两种插件
Publish Over SSH
Maven Integration plugin
3.4、确保插件启用成功
4、jenkins-git账号配置、服务器配置
4.1、git账号配置
进入凭证管理
选择添加凭证
保存git用户名、密码
4.2、服务器配置
进入到系统管理
搜索ssh service
进行服务器配置
5、项目流程配置
5.1 新建工程
5.2 配置工程详情
5.1 空间存放配置
5.1 源码管理配置(1.0和4.1必须配置好)
5.1 构建后端项目打包(2.0需配置好)
来到Build Steps
增加构建步骤选择调用顶层 Maven 目标
5.2 构建完成进行上传(4.2需配置好)
来到Build Steps
增加构建步骤选择Send files or execute commands over SSH
6 踩坑点
6.1、Cannot run program “mvn”
mvn 没安装好
方式一、尝试赋予权限
chmod -R 777 /home/jenkins/apache-maven-3.9.9
方式二、增加软连接
ln -s /home/jenkins/apache-maven-3.9.9/mvn /usr/bin/mvn
[yn_work_src-system] $ mvn -f /home/jenkins/xxxx/pom.xml -D-Dmaven.test.skip=true clean package -P SpringCloud
FATAL: command execution failed
java.io.IOException: error=2, No such file or directory
at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:340)
at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:271)
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1107)
Caused: java.io.IOException: Cannot run program "mvn" (in directory "/home/jenkins/xxxx-system"): error=2, No such file or directory
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1128)
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1071)
at hudson.Proc$LocalProc.<init>(Proc.java:252)
at hudson.Proc$LocalProc.<init>(Proc.java:221)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:994)
at hudson.Launcher$ProcStarter.start(Launcher.java:506)
at hudson.Launcher$ProcStarter.join(Launcher.java:517)
at hudson.tasks.Maven.perform(Maven.java:368)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:818)
at hudson.model.Build$BuildExecution.build(Build.java:199)
at hudson.model.Build$BuildExecution.doRun(Build.java:164)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:526)
at hudson.model.Run.execute(Run.java:1894)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44)
at hudson.model.ResourceController.execute(ResourceController.java:101)
at hudson.model.Executor.run(Executor.java:446)
Build step 'Invoke top-level Maven targets' marked build as failure
Finished: FAILURE
5、技术支持
联系方式:3151519983
创作不易,感谢点赞
创作不易,感谢点赞
创作不易,感谢点赞
创作不易,感谢点赞
创作不易,感谢点赞
创作不易,感谢点赞