jenkins+maven java自动构建环境搭建

目前比较火的自动构建工具Jenkins不用过多介绍了,一款非常强大的CI工具。然后是maven,java的自动构建工具。下面简单介绍一下这两款工具的部署过程

0x01 安装java环境

jenkins和maven都依赖java环境

1
rpm -ivh jdk-8u131-linux-x64.rpm

0x02 安装maven

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
cd /opt
wget http://apache.osuosl.org/maven/maven-3/3.5.2/binaries/apache-maven-3.5.2-bin.tar.gz
tar xf apache-maven-3.5.2-bin.tar.gz
mv apache-maven-3.5.2 maven

vim /etc/profile
#增加maven的环境变量
export MAV_HOME=/opt/maven
export MAV=$MAV_HOME/bin
export MAV_OPTS='-Xms256m -Xmx512m'
export PATH=$MAV:$PATH

#配置maven本地源的路径
vim /opt/maven/conf/settings.xml
#增加以下内容
<localRepository>/data/maven_repo</localRepository>

#测试是否安装成功
source /etc/profile
mvn --version
#出现如下内容说明安装成功了
Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T15:58:13+08:00)
Maven home: /opt/maven
Java version: 1.8.0_131, vendor: Oracle Corporation
Java home: /usr/java/jdk1.8.0_131/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-693.el7.x86_64", arch: "amd64", family: "unix"

0x03 安装Jenkins

为了安全起见,jenkins建议使用非root用户运行

1
2
3
4
5
6
7
useradd jenkins
mkdir /opt/jenkins
cd /opt/jenkins
wget http://mirrors.jenkins.io/war-stable/latest/jenkins.war
chown jenkins.jenkins /opt/jenkins -R
su - jenkins
setsid java -jar /opt/jenkins/jenkins.war >> /opt/jenkins/jenkins.log

打开jenkins页面,首先回提示输入输入随机密码,一般在/home/jenkins/.jenkins/secrets/initialAdminPassword

1
2
cat /home/jenkins/.jenkins/secrets/initialAdminPassword
7bd7d4f5ff244944a9a96754a8e17c84

a

输入随机密码,点击下一步后,提示安装插件,一般点左边这个推荐安装就行
b

出现下面的图就开启等待状态了
c

插件安装完后,按照提示创建管理员帐号
d

配置好管理员帐号后,依次进入Manage Jenkins->Configure Global Security,进入安全设置,开启允许用户注册
e

0%