4, gerrit+jenkins Build CI system

Source: Internet
Author: User

One, CI system process

The developer updates the code in the local git repository to the corresponding project repository on the Gerrit system, which triggers the Gerrit system to send an e-mail notification to Owner,owner at this point to log on to the Gerrit Web page for code Review )。 If the audit passes, the owner commits the submit action. The code for the developer push will then merge (merge) into the corresponding project warehouse on the Gerrit server. If the audit does not pass, the developer needs to modify the code and push again until the audit passes. While Jenkins is triggered by an event on the Gerrit system (either submit or push, which can be set on the Jenkins system itself), the project is built, including compiling, packaging, uploading to the specified service.

The above is the CI system workflow, which can also be added to Jenkins on the code unit testing. The project is built and published to the server only if the test passes. How to do unit test, still in the study.


Ii. CI system environment

Git+gerrit+jenkins (Install Gerrit trigger plug-in)

Gerrit Server: 172.16.206.133

Jenkins Server: 172.16.206.129

Git must be installed on both servers, and their work depends on the GIT environment


There is a document in front of Gerrit and Jenkins, which is not shown here. It is important to note that:

1, installation Gerrit, during the interactive installation process, the system will ask you whether to install the Label verified , the default is not installed, if you want to set up CI, here you need to choose to install. If the system is not installed this thing, later can be installed, but several methods on the internet failed to try, so I can only re-execute the Gerrit installation command: Java-jar/path/to/gerrit.war/path/to/gerrit_dir

Reinstall again, before reloading, first stop the Gerrit Service, the interactive installation process, many steps using the old configuration, except the Label verified Select Y, indicating the installation.


2, Jenkins installation Gerrit trigger plug-in

The Jenkins website introduces the usage of this plugin:

Https://wiki.jenkins-ci.org/display/JENKINS/Gerrit+Trigger#GerritTrigger-Gerritaccessrights



Third, the configuration on the Gerrit

1. Create an account for the Jenkins server on the Gerrit server, such as Jenkins. Use this account to log in to the Gerrit Web and add the account to the system preset non-interactive Users group. By default, the group has the ability to listen to stream events, and the principle of Steam events is that Gerrit receives the code and sends it to Jenkins in the form of an event, triggering Jenkins to build automatically.


2, set the SSH key for the account, the public key under the root account of the Jenkins server is passed to the Gerrit system under the Jenkins account created by the Jenkins server, and if you do not know how to set it, Please refer to the previous Gerrit User Configuration document.

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/80/02/wKiom1c0IzGikDEHAAGKYsri-DI609.png "style=" float: none; "title=" 1.png "alt=" Wkiom1c0izgikdehaagkysri-di609.png "/>

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/80/02/wKiom1c0IzawsTm-AAEqyllq-tg966.png "style=" float: none; "title=" 2.png "alt=" Wkiom1c0izawstm-aaeqyllq-tg966.png "/>


3. Set the permissions of the Non-interactive Users group, which is set on all-projects

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/80/00/wKioL1c0JkeDsx8vAADcPvMmcjY976.png "style=" float: none; "title=" 3.png "alt=" Wkiol1c0jkedsx8vaadcpvmmcjy976.png "/>

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/80/03/wKiom1c0JWeQp2_cAACvDX6WsFw883.png "style=" float: none; "title=" 4.png "alt=" Wkiom1c0jweqp2_caacvdx6wsfw883.png "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/80/03/wKiom1c0JbOiK4zLAAMpgVyiTZs537.png "style=" float: none; "title=" 5.png "alt=" Wkiom1c0jboik4zlaampgvyitzs537.png "/>

note that for the label verified permission, many articles only say to the Non-interactive Users group permission, but test it down, if you do not give administrators and project Owners group verified permissions, the two groups have no submit permission. Because only verified first, there will be submit. Specifically what this verified authority is for. I haven't studied it yet. Should be able to not need this permission, some articles are said to be double protection.


Iv. Configuration on Jenkins

1. Install Gerrit trigger plug-in

System Management ==> Management plugin ==> Optional plugin, search Gerrit Trigger, restart Jenkins after installation


2, configuration Gerrit Trigger

System Management ==>gerrit Trigger==>add New Server

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/80/00/wKioL1c0K6XB84ntAAJgqRXBuBs940.png "title=" 6.png " alt= "Wkiol1c0k6xb84ntaajgqrxbubs940.png"/>

Test success will show success, note hostname Here I fill in the Gerrit server IP, can fill in the hostname, but must be able to parse the line. At this end, the configuration is basically complete.


Create a project that demonstrates how to build a CI environment.

1. Create project on Gerrit, named Citest. Administrators a member within a group to create a project.

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/80/03/wKiom1c0LR-DpIkUAAMKWUyr5nE964.png "title=" 7.png " alt= "Wkiom1c0lr-dpikuaamkwuyr5ne964.png"/>


2. Sign in to Jenkins to create a free-style project

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/80/03/wKiom1c0L2rSjj9dAAJ3Y9EEuTc510.png "title=" 11.png "alt=" Wkiom1c0l2rsjj9daaj3y9eeutc510.png "/>


Source control Here Select the Git,repository URL is the address provided for anonymous users on the Gerrit Web, note the address of the

The git clone command is removed, and the Jenkins server itself has git installed, integrating the GIT environment.

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/80/03/wKiom1c0MLnwT-yVAAH25NzqUlI335.png "style=" float: none; "title=" 12.png "alt=" Wkiom1c0mlnwt-yvaah25nzquli335.png "/>



Build Trigger Select Gerrit Event

Choose a server: Select any server or specific server as appropriate. Here I select the Gerrit Server configured earlier

Trigger on: can not be configured, if not, the event Patchset Created is automatically selected by default when the job is saved (the most critical event is the event that is triggered when the code is submitted (push rather than submit) and Draft Published. I chose change merged, which means that when the code is approved, owner clicks Submit,merge and then starts building.

Gerrit Project: complete Pattern and Branches content is required to be valid, such as type select plain, value fill, Branches type Plain, value fill master, or type select Path,pattern Fill * *, Branches type Select Path,pattern Fill * * Match any project and branch, more detailed description can point the corresponding question mark to view. What other options do you mean you haven't had time to study.

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/80/00/wKioL1c0MZ3igbjCAAKwXLv5uTQ805.png "style=" float: none; "title=" 13.png "alt=" Wkiol1c0mz3igbjcaakwxlv5utq805.png "/>

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/80/03/wKiom1c0ML7xugEGAAFzhFwwryA218.png "style=" float: none; "title=" 14.png "alt=" Wkiom1c0ml7xugegaafzhfwwrya218.png "/>

After the build with email notification, this need to install email related plug-ins, if not clear how to configure, you can view the previous Jenkins related documents.

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/80/03/wKiom1c0MMHTn6gOAALAnI0wWBw964.png "style=" float: none; "title=" 15.png "alt=" Wkiom1c0mmhtn6goaalani0wwbw964.png "/>

Here the CI environment is built.




Six, run a project


1, GIT global configuration, configure the user name and mailbox, here the user name and mailbox must be consistent with the account name mailbox on the Gerrit Web,

Otherwise, the git push command is executed at the wrong times:remote:ERROR:does not match your the user account.

[[Email protected] ~] $git config--global user.name "user1" [[email protected] ~] $git config--global user.email "[Email PR Otected] "[[email protected] ~]$ git config--listuser.name=user1[email protected]


2, log on to the ordinary user user1, the Citest project cloned to the local

[[email protected] ~]$ git clone ssh://[email protected]:29418/citest & & scp -p -p 29418 [email protected]:hooks/commit-msg citest/.git/hooks/ Initialized empty git repository in /home/user1/citest/.git/remote: counting  objects: 2, doneremote: Finding sources: 100%  (2/2) Remote: total  2  (delta 0), reused 0  (delta 0) receiving objects: 100%  (2/2 ), done.commit-msg                                                                            100% 4662     4.6KB/s   00:00    [[email  Protected] ~]$ lscitest


3, enter into the Citest folder, create a new citest.sh file, the contents of the free fill.

[Email protected] citest]$ lscitest.sh


4. Push the file to the Gerrit server

[[email protected] citest]$ git add citest.sh

[[email protected] citest]$ git commit-m "created file citest.sh"

[Master dfd5972] created the file citest.sh

1 files changed, 1 insertions (+), 0 deletions (-)

Create mode 100644 citest.sh

[[email protected] citest]$ git push origin Master:refs/for/master

Counting Objects:4, done.

Writing objects:100% (3/3), 311 bytes, done.

Total 3 (delta 0), reused 0 (Delta 0)

Remote:processing changes:new:1, refs:1, done

Remote

Remote:new changes:

REMOTE:HTTP://172.16.206.133:8081/18 created the file citest.sh

Remote

To Ssh://[email Protected]:29418/citest

* [New branch] master, Refs/for/master


5. Log in to the Web UI for auditing with Gerrit Administrator account

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/80/04/wKiom1c0N8bj6iivAAKJq4ZxzYs219.png "style=" float: none; "title=" 21.png "alt=" Wkiom1c0n8bj6iivaakjq4zxzys219.png "/>

Note that when Code-review, the value range is 2 to +2,-2 is audit does not pass, +2 is audit pass, 1, 0, 1 can only as a reference option option, if you want to pass code audit, must have at least one +2, and can not have-2, two +1 is not equal to +2.


650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/80/04/wKiom1c0N8iQOeiuAAD3Hrd89Ys765.png "style=" float: none; "title=" 22.png "alt=" Wkiom1c0n8iqoeiuaad3hrd89ys765.png "/>

After the administrator has done the code review, he immediately talks about the mail sent from the Gerrit Administrator's mailbox.

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/80/04/wKiom1c0N8niRRYeAAC91RYXdrk004.png "style=" float: none; "title=" 23.png "alt=" Wkiom1c0n8nirryeaac91ryxdrk004.png "/>


When the administrator clicks Submit, the manager immediately starts Jenkins build.

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/80/01/wKioL1c0O_HyxHVAAAJzFLoPjyw714.png "title=" 26.png "alt=" Wkiol1c0o_hyxhvaaajzflopjyw714.png "/>


After the project is built on Jenkins, send an email to the relevant person

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/80/01/wKioL1c0PD-D45qKAAHqL4Ko17g243.png "title=" 25.png "alt=" Wkiol1c0pd-d45qkaahql4ko17g243.png "/>



4, gerrit+jenkins Build CI system

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.