Steps to build a jenkins automated integrated development environment, pure white

1. Why do you need a jenkins automated integrated development environment.

      story background:

        In the process of separating the front and back ends, when the front and back ends are jointly debugged and communicated, the back-end personnel need to package and deploy the code to the test server after the development is completed. This process will cause the back-end personnel to affect the overall efficiency because the code update speed is too slow. This behavior does not meet the four basic advantages of programmers.

        The jenkins automated integrated development solution has existed for a long time. It allows back-end personnel to submit svn code without paying attention to a series of issues such as packaging and deployment. Front-end personnel can obtain the latest test environment, thereby improving development efficiency.

2. How to deploy jenkins.

       2.1. A server (windows/linux system) with JDK/Maven/Tomcat installed

       2.2. Download the latest war package from the jenkins official website, copy it to the webapps of tomcat, and start tomcat.

                apache-tomcat-xxx/bin/startup.bat

               Cloud disk download address:

                  Link: https://pan.baidu.com/s/1nyrIOfHjCdBMELFcdL7k4g 
                 Extraction code: hvog 

       2.3. Visit http://localhost/8080/jenkins/ with a browser, and follow the steps to install jenkins. 

               Default password path /root/.jenkins/secrets/initialAdminPassword

       2.4 After logging in to jenkins, click Manage Jenkins. Configure related information.

 

                 security configuration:

           Deployment Global Tool Configuration:

        

                manager plugins (installation plugins):

                Subversion Plug-in     /    Deploy to container Plugin

 

                The basic configuration is now complete. 

        2.5 Create a new item=> Fill in the project name, select freestyle project, and jump to the following interface after confirming:

                Source code management: Select subversion, fill in the svn source code download address and svn account password, others are default.

                Build Trigger: Select Remote Build. Fill in the value of the token (it must be a token string at this time, not an address)

                The specific access address is: http://ip:port/jenkins/job/project/build?token=xxx

                Build environment: select the maven version, use clean install to build the project

        

                Post-build actions:

               

tomcat needs to be able to access ManagerApp through a browser.

Tomcat 9 only allows local access, which can be modified through {tomcat webapps path}/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|\d+\.\d+\.\d+\.\d+" />
  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.CsrfPreventionFilter\$LruCache(?:\$1)?|java\.util\.(?:Linked)?HashMap"/>
</Context>

 Set tomcat's conf/tomcat-users.xml

  <role rolename="tomcat" />
  <role rolename="manager-gui"/>
  <user username="账号" password="密码" roles="tomcat,manager-gui"/>

  At this time, if you encounter the failure to upload the war package through the browser, it should be a cross-domain problem of tomcat 9, you only need to log out {tomcat webapps path}/manger/WEB-INF/web.xml

<!--
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>HTML Manager interface (for humans)</web-resource-name>
      <url-pattern>/html/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
       <role-name>manager-gui</role-name>
    </auth-constraint>
  </security-constraint>
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>Text Manager interface (for scripts)</web-resource-name>
      <url-pattern>/text/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
       <role-name>manager-script</role-name>
    </auth-constraint>
  </security-constraint>
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>JMX Proxy interface</web-resource-name>
      <url-pattern>/jmxproxy/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
       <role-name>manager-jmx</role-name>
    </auth-constraint>
  </security-constraint>
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>Status interface</web-resource-name>
      <url-pattern>/status/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
       <role-name>manager-gui</role-name>
       <role-name>manager-script</role-name>
       <role-name>manager-jmx</role-name>
       <role-name>manager-status</role-name>
    </auth-constraint>
  </security-constraint>
  -->

    Cancel the above code, but it will lead to insecurity. Please consider other solutions on your own. 

After the above configuration is completed, click Build Now, and jenkins will pull the latest code from the svn service, package it, run it, and publish it to tomcat. 

3. How to write svn hook function. (under the window environment)

        At this point, we have a path that triggers jenkins to automatically package through an external access address. Refer to 2.5 for configuration. 

        How to automatically trigger jenkins package deployment after submission on the windows server? ?

        Next we need a hook function.

        3.1 Open the Repositories/codebase/hooks folder of the server-side svn.

               There are a series of files under this folder. We copy the post-commit.tmpl file and rename it to the post-commit.bat file.

                Comment out the original code in *.bat. At this time, the Windows system of the server needs a toolkit called curl.

                Link: https://pan.baidu.com/s/1VB1Bjmd_w9zTBWNrwQV_9w 
                Extraction code: tqyw 

               Modify the content of the .bat file to:

               

{Curl解压存放位置}\bin\curl.exe -X post -v -u  {jenkins账号}:{jenkins密码}  http://{服务器IP地址}:{端口号}/jenkins/job/{jenkins的项目名}/build?token={自定义的token值}

The above {} and the contents contained therein shall be replaced by yourself.               

At this point our hook function has been edited. Can test whether it is successful!

Guess you like

Origin blog.csdn.net/weixin_59128282/article/details/120089190