Jenkins-Maven项目构建

1、安装JDK

cd /data/softs
tar xf openjdk-11.0.0.1_linux-x64_bin.tar.gz -C /data/server/
ln -s /data/server/jdk-11.0.0.1 /usr/local/java

cat << 'CAT_END' >> /etc/profile
export JAVA_HOME=/usr/local/java
export LS_JAVA_HOME=/usr/share/logstash/jdk
export PATH=$JAVA_HOME/bin:$PATH
CAT_END
source /etc/profile
java -version

2、安装Maven

2.1、下载软件

# 官网地址
https://maven.apache.org/download.cgi

curl -O https://dlcdn.apache.org/maven/maven-3/3.9.2/binaries/apache-maven-3.9.2-bin.tar.gz

2.2、安装软件

tar xvf apache-maven-3.9.2-bin.tar.gz -C /data/server/
ln -s /data/server/apache-maven-3.9.2 /usr/local/maven

cat << 'CAT_END' > /etc/profile.d/maven.sh
export MAVEN_HOME=/usr/local/maven
export PATH=$PATH:$MAVEN_HOME/bin
CAT_END
source /etc/profile.d/maven.sh

2.3、更换maven仓库为阿里云

# vi /usr/local/maven/conf/settings.xml
<mirrors>
...
<mirror>  
    <id>alimaven</id>  
    <name>aliyun maven</name>  
    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
    <mirrorOf>central</mirrorOf>          
</mirror>
...
</mirrors>

# mirror配置一个即可

2.4、查看mvn版本

# mvn -v
Apache Maven 3.9.2 (c9616018c7a021c1c39be70fb2843d6f5f9b8a1c)

3、Jenkins配置maven

3.1、Jenkins增加maven环境变量

3.2、配置全局JDK

3.3、安装maven插件

Maven IntegrationVersion
Pipeline Maven IntegrationVersion

3.4、安装插件完后,会多出一个maven项目

4、Jenkins Java maven项目构建

4.1、准备代码

4.1.1、测试代码下载

sonar插件提供了一个代码库
github:https://github.com/SonarSource/sonar-examples 
软件包下载:https://github.com/SonarSource/sonar-examples/archive/master.zip

# 这里使用java maven测试代码

4.1.2、上传至gitlab

4.2、创建maven项目

4.3、配置git

4.4、指定pod.xml位置

4.5、立即构建

root@localhost:~/.jenkins/workspace/my-maven# ll java-maven-simple/target/
total 28
drwxr-xr-x 6 root root 4096 Jun 20 12:21 ./
drwxr-xr-x 4 root root 4096 Jun 20 12:21 ../
drwxr-xr-x 3 root root 4096 Jun 20 12:21 classes/
-rw-r--r-- 1 root root 2091 Jun 20 12:21 example-java-maven-1.0-SNAPSHOT.jar
drwxr-xr-x 3 root root 4096 Jun 20 12:21 generated-sources/
drwxr-xr-x 2 root root 4096 Jun 20 12:21 maven-archiver/
drwxr-xr-x 3 root root 4096 Jun 20 12:21 maven-status/

 

posted @ 2023-06-20 14:25  小粉优化大师  阅读(545)  评论(0编辑  收藏  举报