Jenkins Continuous integration platform built to commit code via GIT

Source: Internet
Author: User
Tags git client git commands

I. Overview

The previous article introduced Jenkins in conjunction with SVN to build the jar package, this article describes another way in which code commits git, and combines maven to build the code package.

Lab Environment:

ip:10.0.90.27 System: Centos6.6 x86_64

Package:

Jenkins 2.9Tomcat 8.0.36JDK 8.92maven 3.3.9git

Second, installation steps

1. Installing the JDK

#rpm-ivh jdk-8u92-linux-x64.rpm Preparing ... ########################################### [100%] 1:jdk1.8 .0_92 ########################################### [100%]unpacking JAR files ... tools.jar ... Plugi N.jar ... javaws.jar ... deploy.jar ... rt.jar ... jsse.jar ... the charsets.jar ... the local Edata.jar ...

2. Install Tomcat

#tar XF apache-tomcat-8.0.36.tar.gz-c/usr/local/#cd/usr/local/#ln-sv apache-tomcat-8.0.36 Tomcat start #cd tomcat#./bin/ startup.sh Using catalina_base:/usr/local/tomcatusing catalina_home:/usr/local/tomcatusing CATALINA_TMPDIR:/usr/lo Cal/tomcat/tempusing jre_home:/usrusing CLASSPATH:/usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin /tomcat-juli.jartomcat started. Access test: In the browser input http://10.0.90.27:8080, a Tomcat Default Web page appears, indicating that the installation was successful.

3, install Jenkins (installation method is directly extracted into Tomcat)

Copy the Jenkins.war package to the/usr/local/tomcat/webapps directory

And then browser access:

http://10.0.90.27:8080/jenkins/Display the following interface

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/82/F7/wKiom1dnhPGAY4toAACihwxUj-E306.png-wh_500x0-wm_3 -wmp_4-s_2716269078.png "title=" 01.png "alt=" Wkiom1dnhpgay4toaacihwxuj-e306.png-wh_50 "/>

Follow the prompts to get the password from the/root/.jenkins/secrets/initialadminpassword file, and then continue to see the following interface:

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/82/F7/wKiom1dnhVWQd1CNAAER1l50yLM288.png-wh_500x0-wm_3 -wmp_4-s_1162729864.png "title=" 02.png "alt=" Wkiom1dnhvwqd1cnaaer1l50ylm288.png-wh_50 "/>

Then just follow the default selection (install suggested plugins) and proceed to the next step, and you'll see the installation plugin interface:

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/82/F7/wKiom1dnhdSTwmRPAADNLglRFNY225.png-wh_500x0-wm_3 -wmp_4-s_4216107199.png "title=" 03.png "alt=" Wkiom1dnhdstwmrpaadnlglrfny225.png-wh_50 "/>

The process of installing plugin will take some time, please wait patiently ...

PS: If you have been in the installation state (may be due to network reasons, some plugin installed), you can refresh the browser, if prompted after the installation failed, you can click the "Retry" prompt, continue. After installing plugin, you will be asked to create an admin user that you can customize such as:

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/82/F7/wKiom1dnhkbxvaNRAABI4QcUb3o964.png-wh_500x0-wm_3 -wmp_4-s_3271251043.png "title=" 04.png "alt=" Wkiom1dnhkbxvanraabi4qcub3o964.png-wh_50 "/>

You can also continue to use the Admin user, below the Red box button (I am here to create a normal admin user Liguang):

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/82/F6/wKioL1dnhnXB5tjQAAALNYChqzA285.png-wh_500x0-wm_3 -wmp_4-s_3110259601.png "title=" 05.png "alt=" Wkiol1dnhnxb5tjqaaalnychqza285.png-wh_50 "/>

Once created, clicking on the "Save and Finish" button will pop up the following page:

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/82/F6/wKioL1dnhwegm3oEAABBP9O9oh8147.png-wh_500x0-wm_3 -wmp_4-s_1835055491.png "title=" 06.png "alt=" Wkiol1dnhwegm3oeaabbp9o9oh8147.png-wh_50 "/>

Then click on "Start using Jenkins" and you'll see the installed Jenkins interface.

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M02/82/F6/wKioL1dnhzfAZdO_AABw6FDf-nk990.png-wh_500x0-wm_3 -wmp_4-s_4136046570.png "title=" 07.png "alt=" Wkiol1dnhzfazdo_aabw6fdf-nk990.png-wh_50 "/>

You can see which plugins have been installed before, which are successful, and which are not, method: "System Management"--"management plug-in", you will see the interface of the plug-in, you can operate according to the situation.

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/82/F8/wKiom1dnkJGwaZyfAAAmiWn8848065.png-wh_500x0-wm_3 -wmp_4-s_438443894.png "title=" 08.png "alt=" Wkiom1dnkjgwazyfaaamiwn8848065.png-wh_50 "/>

Note: If you want to use SVN to manage the code, but the SVN plugin is not installed, the "Code Management" Settings section appears as none when the new project is created, as follows:

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M02/82/F8/wKiom1dnkXGglB4wAABU6PjOaBc235.png-wh_500x0-wm_3 -wmp_4-s_2157944190.png "title=" 09.png "alt=" Wkiom1dnkxgglb4waabu6pjoabc235.png-wh_50 "/>

This time, you will need to install the SVN plugin.

4, Jenkins installation plug-in

"System Management"--"management plug-in"-"optional plug-in", and then in the upper right corner of the "Filter" box enter SVN, you will see a lot of SVN-related plug-ins, choose to install the following plug-ins:

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/82/F8/wKiom1dnl6eS4YTbAABxU5ae5Mc714.png-wh_500x0-wm_3 -wmp_4-s_4116323555.png "title=" 011.png "alt=" Wkiom1dnl6es4ytbaabxu5ae5mc714.png-wh_50 "/>

Select "Install directly" or "Download to restart after installation" can be, I choose the second one, and then see the following interface, first in the "Waiting" state, after a while is "Installed" status.

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/82/F8/wKiom1dnmHCSbYg7AAA4X_eiPiE952.png-wh_500x0-wm_3 -wmp_4-s_2769676048.png "title=" 12.png "alt=" Wkiom1dnmhcsbyg7aaa4x_eipie952.png-wh_50 "/>

After installation, please note that:

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/82/F7/wKioL1dnmJGQGieFAABJt--QQPc568.png-wh_500x0-wm_3 -wmp_4-s_90345961.png "title=" 13.png "alt=" Wkiol1dnmjgqgiefaabjt--qqpc568.png-wh_50 "/>

Then restart Tomcat, refresh the browser, and go to "plug-in management" to see the SVN installation, as follows, the installation is successful:

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/82/F8/wKiom1dnmjXiCIyQAAAgs4crg3M540.png-wh_500x0-wm_3 -wmp_4-s_996678821.png "title=" 14.png "alt=" Wkiom1dnmjxiciyqaaags4crg3m540.png-wh_50 "/>

PS: At this point, in the Test_app project in the "Source Management" section, you will see "None" and "Subversion" exist! But most of the time we also use CVS or git to pull the code, so we need to install the 2 plugins. Install CVS (CVS plug-in) and git (git plugin) plug-ins, as in the same way, you need to restart Tomcat to take effect, after the installation is complete, in the project configuration, you can see, as follows:

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/82/F9/wKioL1dnplaR_UTpAABvUuKkZqQ413.png-wh_500x0-wm_3 -wmp_4-s_3285272904.png "title=" 15.png "alt=" Wkiol1dnplar_utpaabvuukkzqq413.png-wh_50 "/>

In this way, there are 4 ways to manage the source code!

5. View Jenkins ' global Tool Configuration

"System Management"---"Global Tool Configuration" such as:

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/82/FB/wKiom1dnuBeR4zH0AAAn643nTHg479.png-wh_500x0-wm_3 -wmp_4-s_2923152151.png "title=" 18.png "alt=" Wkiom1dnuber4zh0aaan643nthg479.png-wh_50 "/>

As you can see, the Jenkins server does not have Git installed, cannot find Git commands, and then describes how to install Git.

Third, configure Jenkins to pull the replacement code by git

Note: Gitlab installation configuration is not described here (if and Jenkins installed to the same server, you need to be aware that the port does not conflict)
1. Generate key on Jenkins server

#ssh-keygen -t rsa       # #不需要设置密码, return to generating public/ Private rsa key pair. enter file in which to save the key  (/ROOT/.SSH/ID_RSA):  Enter  passphrase  (empty for no passphrase): enter same passphrase  Again: your identification has been saved in /root/.ssh/id_rsa. your public key has been saved in /root/.ssh/id_rsa.pub.the key  Fingerprint is:5a:f1:2f:5c:78:26:26:0d:a4:43:e7:bf:c8:a0:91:e9 [email protected]the key ' s  RANDOMART IMAGE IS:+--[ RSA 2048]----+|      . o         | |      . =         | |       o +         | |      o . * .     | |     + . s b +    | |    . o = = b     | |     e . o + .    | |            .     | |                  |+------ -----------+

2. Install the GIT client command on the Jenkins server and I am here to install the Yum directly

#yum Install git-y view version: #git--versiongit version 1.7.1

After the installation, and then to the global Tool configuration view, there will be no two. 5 Hints of error. By the way, name is set to git1.7.1, and Path to Git executable remains the same.

3. View project information on Gitlab (I used the previously built Gitlab, the address is 10.0.18.173), here is an example of the SERVER1/CSS project:

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/82/FC/wKiom1dn2qKgOoN5AABCeohRY98231.png-wh_500x0-wm_3 -wmp_4-s_3947590704.png "title=" 111.png "alt=" Wkiom1dn2qkgoon5aabceohry98231.png-wh_50 "/>

The red box gives the way to access the code, we use Git, so it needs to be configured as [email protected]:server1/css.git, can also be a domain name: [email protected]:server1/css.git

4, in the Jenkins project configuration, take Test_app as an example,

However, after the configuration, the following problems were encountered:

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M00/82/FB/wKiom1dnuhzRcH8SAACMm2ez6bU264.png-wh_500x0-wm_3 -wmp_4-s_3995333167.png "title=" 17.png "alt=" Wkiom1dnuhzrch8saacmm2ez6bu264.png-wh_50 "/>

Reason: According to the error prompt, found that there is no permission to the Gitlab server-side pull code, you need to the Jenkins service side just generated id_rsa.pub configuration in one can log into the Gitlab user's SSH Keys, the method is as follows:

Use a user to log on to Gitlab, and this user has read and write access to all items on the Gitlab, and then adds the Jenkins key

Click "Profile Settings" on the top right, and then click "SSH Keys" on the popup page, the following screen will appear:

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M00/82/FB/wKiom1dnvC-jdT-MAABBAiKPNMo773.png-wh_500x0-wm_3 -wmp_4-s_3109515046.png "title=" 20.png "alt=" Wkiom1dnvc-jdt-maabbaikpnmo773.png-wh_50 "/>

Click "Add SSH Key", customize the title, paste the Key into the box below, click "Add Key", such as:

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M00/82/FB/wKioL1dnvNSQaYrGAAB66q7Ktow035.png-wh_500x0-wm_3 -wmp_4-s_2941780779.png "title=" 21.png "alt=" Wkiol1dnvnsqayrgaab66q7ktow035.png-wh_50 "/>

Then refresh the Jenkins page, above three. 4 error page, no more error!

PS: If after installing Jenkins, you configure the normal user and set up the mailbox, after adding a good key, the system will send you an email notifying you, the following:

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M02/82/FB/wKioL1dnvbDCGFTnAAAmAxFDpuw048.png-wh_500x0-wm_3 -wmp_4-s_208884384.png "title=" 22.png "alt=" Wkiol1dnvbdcgftnaaamaxfdpuw048.png-wh_50 "/>

5. Add a code branch to the project

First, look at the code branch from Gitlab and then add a branch to each of Jenkins's projects to test_app the project as an example, as follows:

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/82/FB/wKioL1dnxMngKvJ7AABhB6g9kO0829.png-wh_500x0-wm_3 -wmp_4-s_1204348487.png "title=" 23.png "alt=" Wkiol1dnxmngkvj7aabhb6g9ko0829.png-wh_50 "/>,

Add and then apply and save!.

PS: Only one branch can be configured per build!

6, other configuration:

You can configure the old build to be discarded because it is useless to keep too much.

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/82/FC/wKiom1dnxyqDScVEAAA0XBPdGJs860.png-wh_500x0-wm_3 -wmp_4-s_980298085.png "title=" 24.png "alt=" Wkiom1dnxyqdscveaaa0xbpdgjs860.png-wh_50 "/>


This article from the "Knowledge System" blog, reproduced please contact the author!

Jenkins Continuous integration platform built to commit code via GIT

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.