Configure maven under jenkins

1. First install maven on the jenkins server

Download-unzip-rename-start

[root@VM-0-12-centos local]# wget https://mirrors.aliyun.com/apache/maven/maven-3/3.9.0/binaries/apache-maven-3.9.0-bin.tar.gz
[root@VM-0-12-centos local]# tar xf apache-maven-3.9.0-bin.tar.gz
[root@VM-0-12-centos local]# mv apache-maven-3.9.0 maven-3.9.0

set environment variables

[root@VM-0-12-centos local]# vi /etc/profile
export JAVA_HOME=/usr/local/jdk
export MAVEN_HOME=/usr/local/maven-3.9.0
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin:$MAVEN_HOME/bin
export PATH=$PATH:/usr/local/gradle-8.0/bin

start up

[root@VM-0-12-centos local]# source /etc/profile

insert image description here
Check if the installation is successful

[root@VM-0-12-centos local]# mvn -v

Successful installation

2. Add Jenkins global variables

Manage Jenkins->Configure System->Global Properties, add three global variables
JAVA_HOME, M2_HOME, PATH+EXTRA
insert image description here

3. Global tool configuration associated with Maven

Manage Jenkins->Global Tool Configuration->Maven->Add Maven, the configuration is as follows:
insert picture description here

4. Modify Maven's settings.xml

Create a local warehouse directory

[root@VM-0-12-centos /]# mkdir /root/repo

Modify the configuration file

[root@VM-0-12-centos conf]# vi /usr/local/maven-3.9.0/conf/settings.xml

Add to

<localRepository>/root/repo/</localRepository>

Modify the mirror address

    <mirror>
      <id>nexus-aliyun</id>    
      <mirrorOf>*</mirrorOf>    
      <name>Nexus aliyun</name>    
      <url>http://maven.aliyun.com/nexus/content/groups/public</url>
    </mirror>

View the changed section
insert image description here

5. Check whether the configuration is successful in jenkins

Configure the shell script in the project

echo "构建开始"
mvn clean package
echo "构建结束"

insert image description here
Build
Check the build log
insert image description here
and the corresponding war package is generated under the server
insert image description here

Guess you like

Origin blog.csdn.net/weixin_43466526/article/details/129030051