51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

jenkins配置Maven

下载Maven 3.6.3并且上传到centos7

|---------------------|------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 | hljs shell #解压 tar -zxvf apache-maven-3.6.3-bin.tar.gz #建立目录 mkdir /opt/maven #移动 mv apache-maven-3.6.3/* /opt/maven/ |

最后就是这样

opt/maven

配置环境变量

|-----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 | hljs shell vim /etc/profile #到最下面追加环境变量 export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk export MAVEN_HOME=/opt/maven export PATH=$PATH:$JAVA_HOME/bin:$MAVEN_HOME/bin #使环境变量生效 source /etc/profile |

环境变量

最后输入

|-------------|-------------------------------------------| | 1 2 | hljs shell #查看maven版本 mvn -version |

就是这个样子

mvn -version

我们回到Jenkins

找到Global Tool Configuration

Global Tool Configuration

开始配置JDK

jdk

配置Maven

maven

然后保存,到我们的系统配置

系统配置

配置jenkins用到的环境变量

|---------------------|--------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 | hljs shell JAVA_HOME /usr/lib/jvm/java-1.8.0-openjdk M2_HOME /opt/maven PATH+EXTRA $M2_HOME/bin |

环境变量

保存

更改maven仓库地址

|-----------------|--------------------------------------------------------------------------------------| | 1 2 3 4 | hljs shell #创建仓库目录 mkdir /root/repo #更改配置文件 vim $MAVEN_HOME/conf/settings.xml |

更改本地

123

|-------------|----------------------------------------------------------------------------------| | 1 2 | hljs xml <!--修改maven仓库地址--> <localRepository>/root/repo</localRepository> |

更换远程

settings.xml

|------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | hljs xml <mirror> <id>aliyunmaven</id> <mirrorOf>*</mirrorOf> <name>阿里云公共仓库</name> <url>https://maven.aliyun.com/repository/public</url> </mirror> <mirror> <id>aliyunmaven</id> <mirrorOf>*</mirrorOf> <name>阿里云谷歌仓库</name> <url>https://maven.aliyun.com/repository/google</url> </mirror> <mirror> <id>aliyunmaven</id> <mirrorOf>*</mirrorOf> <name>阿里云阿帕奇仓库</name> <url>https://maven.aliyun.com/repository/apache-snapshots</url> </mirror> <mirror> <id>aliyunmaven</id> <mirrorOf>*</mirrorOf> <name>阿里云spring仓库</name> <url>https://maven.aliyun.com/repository/spring</url> </mirror> <mirror> <id>aliyunmaven</id> <mirrorOf>*</mirrorOf> <name>阿里云spring插件仓库</name> <url>https://maven.aliyun.com/repository/spring-plugin</url> </mirror> <mirror> <id>alimaven</id> <mirrorOf>central</mirrorOf> <name>aliyun maven</name> <url>https://maven.aliyun.com/nexus/content/groups/public</url> </mirror> |

完成后,回到jenkinstest02项目配置

找到构建->增加构建步骤->Execute shell

构建

然后输入命令

|-----------|-------------------------------------| | 1 | hljs shell mvn clean package |

保存

点击保存,然后点击左侧的Build Now,出现Build success就成功了~

build success

我们可以看到target目录,下面有刚刚打好的jar包

jar包

重复上面的步骤,再打个war包放tomcat上跑

image-20200715202230881

赞(4)
未经允许不得转载:工具盒子 » jenkins配置Maven