Jenkins构建maven项目
准备工作:
若Jenkins是全新安装,则要构建maven项目,还应在服务器上安装jdk和maven并进行配置。(这里jdk的安装不作介绍)
安装maven
[root@ipha-dev71-1 local]# cd /usr/local [root@ipha-dev71-1 local]# mkdir maven [root@ipha-dev71-1 local]# ll total 12740 drwxr-xr-x. 2 root root 6 Nov 5 2016 bin drwxr-xr-x. 2 root root 6 Nov 5 2016 etc drwxr-xr-x. 2 root root 6 Nov 5 2016 games drwxr-xr-x. 2 root root 6 Nov 5 2016 include drwxr-xr-x. 2 root root 6 Nov 5 2016 lib drwxr-xr-x. 2 root root 6 Nov 5 2016 lib64 drwxr-xr-x. 2 root root 6 Nov 5 2016 libexec drwxr-xr-x 2 root root 6 Aug 12 16:34 maven drwxrwxr-x 6 500 500 108 Aug 7 00:02 node -rw-r--r-- 1 root root 13043892 Aug 7 00:03 node-v10.16.2-linux-x64.tar.xz drwxr-xr-x 7 root root 100 Jan 25 2019 python3 drwxr-xr-x. 2 root root 6 Nov 5 2016 sbin drwxr-xr-x. 5 root root 49 Jan 22 2018 share drwxr-xr-x. 2 root root 6 Nov 5 2016 src [root@ipha-dev71-1 local]# cd maven/ [root@ipha-dev71-1 local]# wget http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.1/binaries/apache-maven-3.6.1-bin.tar.gz --2019-08-12 16:37:36-- http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.1/binaries/apache-maven-3.6.1-bin.tar.gz Resolving mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)... 101.6.8.193 Connecting to mirrors.tuna.tsinghua.edu.cn (mirrors.tuna.tsinghua.edu.cn)|101.6.8.193|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 9136463 (8.7M) [application/x-gzip] Saving to: ‘apache-maven-3.6.1-bin.tar.gz’ 100%[==============================================================================================================================>] 9,136,463 27.7MB/s in 0.3s 2019-08-12 16:37:44 (27.7 MB/s) - ‘apache-maven-3.6.1-bin.tar.gz’ saved [9136463/9136463]
[root@ipha-dev71-1 maven]# tar -xvf apache-maven-3.6.1-bin.tar.gz
[root@ipha-dev71-1 apache-maven-3.6.1]# pwd
/usr/local/maven/apache-maven-3.6.1
[root@ipha-dev71-1 apache-maven-3.6.1]# vim /etc/profile # 配置环境变量,添加如下两行
export MAVEN_HOME=/usr/local/maven/apache-maven-3.6.1
export PATH=$MAVEN_HOME/bin:$PATH
[root@ipha-dev71-1 apache-maven-3.6.1]# source /etc/profile # 使环境变量生效
[root@ipha-dev71-1 apache-maven-3.6.1]# mvn -v # 检测maven是否安装成功
Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-05T03:00:29+08:00)
Maven home: /usr/local/maven/apache-maven-3.6.1
Java version: 1.8.0_112, vendor: Oracle Corporation, runtime: /mnt/yyspace/soft/jdk1.8.0_112/jre
Default locale: en_US, platform encoding: UTF-8
然后在Jenkins的 系统设置-系统管理-全局工具配置 配置jdk与maven
至此,构建maven项目的准备工作已完成。
1.新建一个 maven项目 的任务(若没有下图中的maven项目选项,则需要从系统设置-插件管理 安装插件Maven Integration plugin)
2.配置git
3.配置build
4.执行构建就可以啦
踩坑是成长最快的方式