Jenkins + maven + Git source code to achieve the deployment and release

First, install the necessary plug-ins
  1. Git plugin, source code using the pull
  2. deploy plug-ins, use the application published to Tomcat
Two, Jenkins global configuration (Global Tool Configuration)

Manage Jenkins in [] - configuration Maven, Jdk, Git, etc. [Global Tool Configuration]. Interface is as follows:
Here Insert Picture Description

  1. Maven Configuration

    Maven configuration, select Maven own installation and configuration corresponding setting.xml path.
    Here Insert Picture Description

  2. JDK
    configuration path to the JDK installation, the name can be customized.
    Here Insert Picture Description

  3. Git
    default configuration can be.
    Here Insert Picture Description

  4. Maven installation configuration
    Here Insert Picture Description

Third, create a pipeline project
  1. Creating a project
    Click [Home] - [New Item] to enter the project to create a page, fill in the name, select "Freestyle project", then click "OK" and to go to the next step.
    Here Insert Picture Description

  2. Project General configuration
    Here Insert Picture Description

  3. Source Code Management
    this step you need to install Git plugin, otherwise Git option does not appear, the steps to install the plug will not be repeated here. Here choose Git, and then configure the Git repository path, and then add Credentials, if not created, you can "Add" to add.Here Insert Picture Description

  4. Build Configuration
    configuration commands to build the project by Maven.
    Here Insert Picture Description

  5. Post-build Actions Configuration
    Here is the configuration required to publish the Tomcat. First need to install the plug-deploy, otherwise there is no "Deploy war / ear to a container " option.
    Here Insert Picture Description
    First, you need to configure Tomcat administrator user, that tomcat-users.xml configuration file, add the following configuration:

    <role rolename="manager-gui"/>
      <role rolename="manager-script"/>
      <role rolename="manager-jmx"/>
      <role rolename="manager-status"/>
      <role rolename="manager"/>
      <role rolename="admin"/>
      <user username="admin" password="admin" roles="manager-gui,manager-script,manager-jmx,manager-status,admin,manager"/>
    

Then restart the Tomcat. Access through the browser, as shown in FIG.

注:该Tomcat不是部署Jenkins的Tomcat。

Here Insert Picture Description
配置Deploy war/ear to a container相关参数,如下图所示:
其中,War/EAR files指的是maven构建之后的路径,Context path指的是发布后的访问路径,Container指的是web服务器,Manager user name 指的是tomcat的管理用户名,Manager password是Tomcat管理员密码,Tomcat URL指Tomcat的访问的根目录。

Here Insert Picture Description

四、构建项目

通过【My Views】选择指定的流水线项目,进入到该项目中,如下图所示。
Here Insert Picture Description
然后,点击【Build Now】开始构建项目,这个时候会出现新的构建记录, 如下图所示,通过“Console Output”可以查看,构建日志。

注:构建记录,红色表示构建识别,蓝色构建成功,闪烁状态表示正在构建中。

Here Insert Picture Description
Here Insert Picture Description

五、异常记录

1. ERROR: Error cloning remote repo 'origin’
Here Insert Picture Description
一般都是Git 用户密码不正确造成的。

2. Server returned HTTP response code: 403 for URL: http://xxxx

该错误存在两种可能性:
1、上述提到的Tomcat管理员用户权限不够
2、远程的Tomcat没有开启远程发布的权限。
第一种情况,按照上述得修改即可。第二种情况,根据下面方式修改:
1>、修改tomcat /webapps/manager/META-INF/context.xml的文件,
把下列内容

	<Context antiResourceLocking="false" privileged="true">
	  <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
	</Context>

改成下面内容即可:

<Context antiResourceLocking="false" privileged="true">
  <!--
    <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
    -->
</Context>

参考文档:《The username you provided is not allowed to use the text-based Tomcat Manager (error 403) when deploying on remote Tomcat8 using Jenkins》

No! Valid crumb WAS included 3. in at The Reques
Jenkins put a token in the name of .crumb http request header. When using a reverse proxy, check if Jenkins setting the "Prevent Cross Site Request Forgery exploits" , the proxy server will think .crumb illegal and removed the head, resulting in a jump failure.
Solution:
uncheck "Prevent Cross Site Request Forgery exploits" in Jenkins global security settings, as shown below:
Here Insert Picture Description
4. FAIL - the Application AT the Deployed context path / jeesite-context failed The iCity But to Start
  When Jenkins build time report this error is usually a problem because the code itself, can put the package into the local Jenkins lay vessel verify.

Published 48 original articles · won praise 3 · Views 3115

Guess you like

Origin blog.csdn.net/hou_ge/article/details/103482974