Ten programmers dark horse power of micro-services project development practice, use Jenkins to achieve continuous integration (XXII)

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/Eknaij/article/details/95938811

A, Jenkins Introduction

Jenkins is an open source, scalable, continuous integration, delivery, deployment (compilation Software / code, package, deploy) platform for web-based interface. Allows continuous integration and continuous delivery of projects, no matter what the platform, build or continuous integration can handle any type.

Official website: https: //jenkins.io/ official document: https: //jenkins.io/doc/

Second, characteristics

  • Easy to install: just a java -jar jenkins.war, after the file is downloaded from the official website, run directly, without additional installation, but without having to install the database;
  • Easy Configuration: provides a friendly GUI configuration interface;
  • Change support: Jenkins from the code repository (Subversion / CVS) obtain and generate the code to update the list and output to the compiler output information;
  • Support Permanent link: Jenkins users to access via web, and these links are permanent address of a web page link address, so you can use this link directly in the various documents;
  • Integrated E-Mail / RSS / IM: When completed once integrated, real-time integration of these tools tell you the results
  • JUnit / TestNG test report: that is, to form charts provide detailed test reporting;
  • Support distributed build: Jenkins can work to build integrated distributed to multiple computers to complete;
  • File fingerprint information: Jenkins will save what time integration build produced which jars files, which once integrated built using which version of jars files build records;
  • Support third-party plug-ins: makes Jenkins has become more and more powerful

Third, the installation

1. Install the JDK

Since jenkins developed based on JAVA, so you need to install JDK
(1) Go to the official website of the installation, download and install JDK1.8, Download point I went to
choose:
Here Insert Picture Description
(2) will be downloaded JDK uploaded to the virtual machine
Here Insert Picture Description
(3) the installation command

rpm -ivh jdk-8u211-linux-x64.rpm

Here Insert Picture Description
Input java -version, you can see the version information for a successful installation
Here Insert Picture Description

2. Install jenkins

(1) Enter the following command to install
install wget

yum  -y install wget

Download jenkins use weget

wget https://pkg.jenkins.io/redhat/jenkins-2.185-1.1.noarch.rpm

(2) Installation jenkins

rpm -ivh jenkins-2.185-1.1.noarch.rpm

(3) In order to avoid conflict with the port number for the tomcat, modify the port number jenkins

vi /etc/sysconfig/jenkins

modify

JENKINS_USER="root"
JENKINS_PORT="8235"

Ports can be used freely, without conflict like
Here Insert Picture Description
(4) to start the service
systemctl Start Jenkins
(. 5) access http://192.168.192.130:8235
Here Insert Picture Description
Secrets / initialAdminPassword acquired initial password strings from / var / lib / jenkins /
terminal option Input: cat /var/lib/jenkins/secrets/initialAdminPassword
(6) plug
Here Insert Picture Description
wait for the installation to complete:
Here Insert Picture Description
select to install the recommended plug-ins
(7) establish an admin user
and then all the way to the next step to reach the main interface:
Here Insert Picture Description

3. Install the plug-in

(1) Installation Maven plug
click on the main interface Manage Jenkins, into the management interface
Here Insert Picture Description
selection widget manager
Here Insert Picture Description
to select images from the following maven plug installation:
Here Insert Picture Description
displays the following installation is complete:
Here Insert Picture Description

III. Global Configuration Tool

1. Install Maven local repository

(1) the maven installation package uploaded to the virtual machine (I downloaded the 3.6.1 version)
(2) unzip

tar -zxvf apache-maven-3.6.1-bin.tar.gz

(3)移动目录

mv apache-maven-3.6.1 /usr/local/maven

(4)编辑setting.xml配置文件

 vi /usr/local/maven/conf/settings.xml

配置本地仓库目录,内容如下

<localRepository>/usr/local/repository</localRepository>

(5)将开发环境的本地仓库上传至服务器(虚拟机)并移动到/usr/local/repository 。

mv reponsitory /usr/local/repository

执行此步是为了以后在打包的时候不必重新下载,缩短打包的时间。
(6)编辑setting.xml配置文件 vi /usr/local/maven/conf/settings.xml

<pluginGroups>
<pluginGroup>com.spotify</pluginGroup>
</pluginGroups>

2. 安装git

yum install git

3.全局工具配置

在jenkins住页面中选择系统管理,全局工具配置
(1)JDK配置
jdk configuration
(2)git配置
Here Insert Picture Description
(3)Maven配置
Here Insert Picture Description
配置完后保存

四、持续集成

1、创建任务

(1)回到首页,点击新建按钮 .如下图,输入名称,选择创建一个Maven项目,点击OK
Here Insert Picture Description
为什么是config?因为在上一篇文章中,我们构建docker镜像的时候,给config添加好了相关依赖,所以这里还是继续选择config
点击确定,跳转到源码管理
(2)源码管理
前提是已经将代码上传到git仓库中,可以选择码云或者github,我已将代码上传到gitHub,所以这里用的是github上的url(使用github连接速度较慢,建议还是用码云或者自己搭建一个)
Here Insert Picture Description
(3)Build
Here Insert Picture Description

clean package docker:build -DpushImage

用于清除、打包,构建docker镜像
最后点击“保存”按钮

2.执行任务

回到jenkins的首页,点击启动按钮:
Here Insert Picture Description
可以看到这里的状态
Here Insert Picture Description

构建时出现以下错误:

Here Insert Picture Description
进入相关文件夹查看发现路径不对:
Here Insert Picture Description
返回首页修改item的Build为:
tesquare_parent/tesquare_config/pom.xml
Here Insert Picture Description

Build again:
...
there is a new problem:
ERROR: Failed to parse POMs
it is estimated that when the local repository configuration in addition to the problem, the path's true, but that does not recognize, no way, the last direct with the default repositories, build time needed to download dependencies, time may be longer:
Here Insert Picture Description
If the bit error:
Maven error: Failed to the Execute. Goal ON Project: could not Resolve the Dependencies for Project
Ali cloud, modify / usr / lcoal / maven / conf remember to change my remote repository, it is recommended here at the settings file, add mirrors inside:

<mirror>  
	<id>alimaven</id>  
	<name>aliyun maven</name>  
	<url>http://maven.aliyun.com/nexus/content/groups/public/</url>  
	<mirrorOf>central</mirrorOf>          
</mirror>

See this is to build a success
Here Insert Picture Description

3. View Mirror

(1) Input browser: http: //192.168.192.130: 5000 / v2 / _catalog
Here Insert Picture Description

(2)docker images

Here Insert Picture Description
(3) create the container

docker run -d --name=tensquare_config -p 12000:12000 192.168.192.130:5000/tensquare_config:1.0-SNAPSHOT

(4) Input browser: http://192.168.192.130:12000/user-dev.ymlsee the following:

Here Insert Picture Description
Instructions for running a successful, continuous integration work completed so far!

4. The preceding steps, continuous integration and services other widgets

Note: the need for changes to the pom.xml, the center of each micro-configuration of IP services uri wanted to change the IP of the virtual machine, and the address on github service center in Eureka

The final results shown in Figure:
Here Insert Picture Description

Eureka I changed the port number 9761, turned out to be 6868
Jenkins table:
Here Insert Picture Description

Complete project source code uploaded github, source address

Guess you like

Origin blog.csdn.net/Eknaij/article/details/95938811