CI system build: Five. Gitlab, Gerrit, Jenkins integration of the three automated continuous integration test

Source: Internet
Author: User
Tags ssh git clone
CI System Build: I. Basic Environment setting, Planning CI system construction: two. Gitlab installation CI system set up: three. Gerrit installation CI system set up: four. Installation configuration for Jenkins

Directory 1 Gerrit and Jenkins consolidation 2 Gitlab for some preparations for OpenStack Project 2.1. Gitreview 2.2. testr.conf 3 Gerrit Some preparations for the OpenStack Project 3.1 in The Gitlab project on the Gerrit OpenStack Project 3.2 clone–bare Gerrit on the Gerrit 3.3 sync OpenStack to Gitlab project directory on the 4 OpenStack Create build task on OpenStack project on Nkins 5 submit Review Tasks Gerrit and Jenkins consolidation

Let Gerrit support Jenkins,gerrit after the 2.7 release of the ' lable verified ', need to add their own

# cd/tmp
# git init cfg; CD cfg
# git config user.name ' admin '
# git config user.email ' admin@thstack.com ' 
  # git remote add Origin ssh://admin@review.thstack.com:29418/all-projects
# Git pull Origin
refs/meta/config # vim Project.config        # Add the following 5 lines at the end of the file
[label ' verified ']
    function = Maxwithblock
    value =-1 fails
    val UE =  0 No score
    value = +1 verified
# git commit-a-m ' Updated permissions '
# Git push Origin Head:re Fs/meta/config

View Jenkins Log discovery will always appear the following information, because Jenkins does not have the authority to monitor Gerrit ' Stream Events '

# tail-f/var/log/jenkins/jenkins.log 
Dec, 2013 1:16:49 AM Com.sonyericsson.hudson.plugins.gerrit.gerritevents.GerritHandler run
Info:ready to receive the data from Gerrit
Dec, 2013 1:16:49 AM Com.sonyericsson.hudson.plugins.gerrit.gerritevents.GerritHandler Run
Info:ready to receive data from Gerrit

Gerrit ' Stream Events ' actions are visible in the Gerrit global settings are open to the ' non-interactive Users ' GROUP by default

Login to the Gerrit system with admin@thstack.com users, add Jenkins@thstack.com users to the ' Non-interactive users ' group

Click-> people-> List Groups-> non-interactive Users

Now submit the Review request only code RIVEW Audit, we require Jenkins verified and code Review double Protection, in the Projects Access bar, for reference:refs/h eads/Items Add verified feature *

Click Projects-> Access-> Edit-> Find reference:refs/heads/* entry-> Add Permission-> Label verified-> Gro Up Name Enter non-interactive Users-> Add-> to click Save Changes at the bottom gitlab some preparation for the OpenStack project . Gitreview

Before the CI system was built: two. Gitlab installation configuration article in the Gitlab created a called OpenStack project, and set permissions, ordinary users do not have the means to push, can only use the GIT Review command to submit. The GIT Review command requires the. gitreview file to exist in the project directory and add the. gitreview file to the admin@thstack.com user.

git clone git@gitlab.thstack.com:devgroup/openstack.git
cd openstack
git config user.name ' admin '
git Config user.email ' admin@thstack.com '

Edit. gitreview file

Vim. Gitreview
[Gerrit]
host=review.thstack.com
port=29418
project=openstack.git

Add to Version Library

git Add. Gitreview
git commit. gitreview-m ' Admin Add. gitreview file. '
Git push Origin Master
. testr.conf

Python code I use the TESTR, I need to install the TESTR command first

Apt-get Install PYTHON-PIP
pip install testrepository

Add the. testr.conf file in OpenStack this project

CD OpenStack
vim. testr.conf
[DEFAULT]
test_command=os_stdout_capture=1 os_stderr_capture=1 os_test_ Timeout=60 ${python:-python}-M Subunit.run discover-t././$LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE C4/>test_list_option=-list

Submit to version Library

git Add. testr.conf
git commit. testr.conf-m ' Admin Add. testr.conf file '
git push Origin master
some preparations for the OpenStack project on Gerrit Create a OpenStack project on Gerrit

To know review is on the Gerrit, and Gerrit is now no project, want to let Gitlab project on Gerrit Review, must create the same project on the Gerrit, and have the same warehouse files.

Create a OpenStack project on Gerrit with the Admin user

Ssh-p 29418 admin@review.thstack.com Gerrit Create-project OpenStack
Clone–bare Gitlab on the warehouse to Gerrit

Clone Gitlab's OpenStack project on Gerrit

Cd/etc/gerrit/git
rm-fr openstack.git
git clone--bare git@gitlab.thstack.com:devgroup/openstack.git
Synchronize Gerrit OpenStack items to OpenStack project directory on Gitlab

After the user git review, the code passes the Jenkins test, the artificial review, the code only merges into the Gerrit OpenStack project, and does not merge into Gitlab OpenStack project, so needs to be Gerrit OpenStack The Project warehouse is automatically synchronized to the OpenStack Project warehouse of the Gitlab when there is a change. Gerrit comes with a Replication function, and we install this Plugin by default when we install Gerrit. Now you just need to add a replication.config to Gerrit.

Add Replication.config File

Vim/etc/gerrit/etc/replication.config
[remote "OpenStack"]
  # Gerrit The name of the item to be synchronized      
  projects = OpenStack
  url = root@gitlab.thstack.com:/home/git/repositories/devgroup/openstack.git
  push = +refs/heads/*:refs/heads/*
  push = +refs/tags/*:refs/tags/*
  push = +refs/changes/*:refs/changes/*
  threads = 3

The above URL is to use root user to do Gerrit OpenStack project copied to the Gitlab OpenStack Project, need password-free login, generate key

Ssh-copy-id-i gitlab.thstack.com  # Enter root user password

Set ~/.ssh/config

Vim ~/.ssh/config
Host gitlab.thstack.com:
    identityfile ~/.ssh/id_rsa
    preferredauthentications PublicKey

In ~/.ssh/known_hosts, add the RSA key to Gitlab.thstack.com

> ~/.ssh/known_hosts
ssh-keyscan-t RSA gitlab.thstack.com > ~/.ssh/known_hosts
ssh-keygen-h-F ~/.ssh/ Known_hosts

Restart the Gerrit service

/etc/init.d/gerrit restart

Gerrit replication is configured and there is a ${name} variable in the Gerrit document that is used to replicate all Gerrit items, not needed here. If you have multiple items that need to be replicated, add more than one [remote ...] field to Replication.config. Be sure to follow the steps above to configure the replication functionality. Create a build task on the OpenStack project on Jenkins

Login with Admin user Jenkins, create build task for OpenStack project click New-> Enter task Name-> Select Build a free-style software project

Select ' Git '-> in ' Repository url ' to enter the address of the OpenStack project on Gerrit (there are specific URLs in Gerrit behind OpenStack's project list) -> Enter ' origin/$GERRIT _branch ' in ' branches to build '

Select Gerrit Event-> Click Add to add ' Patchset Created ' and ' Draft published '-> in the first plain enter project name OpenStack, second plain input ma  Ster-> Click Add Build Step-> Select ' Execute shell '-> write script to be tested-> save you can also choose ' Add build post step ' to email notification of a group and other functions. Submit Review Tasks

Switch to Longgeek user, before creating a Longgeek user to facilitate testing

Su-longgeek
cd OpenStack   # before adding a testfile file, push does not have permissions, so use git review instead of git push git
push git
review
creating a git remote called Gerrit that maps to:
    ssh://longgeek@review.thstack.com:29418/openstack.git
Your Change is committed before the commit hook was installed
amending the commit to add a Gerrit change ID
remot E:processing changes:new:1, refs:1, done    
remote: 
remote:new changes:
Remote:   http:// REVIEW.THSTACK.COM/1
Remote: to 
ssh://longgeek@review.thstack.com:29418/openstack.git
* [New Branch] Head      -> refs/for/master/master

Login with Admin user http://review.thstack.com can see Longgeek user submitted Reivew request

You can see the Jenkins has passed, and put on the ' green Tick ' mark, next Admin user +2 and submit can Merge code

After the Merge code, Gerrit is automatically synchronized to the Gitlab, as shown in the following figure

After synchronization, you can use the git pull command to code from the OpenStack warehouse on Gitlab

CD OpenStack
git pull from
gitlab.thstack.com:devgroup/openstack
   70c59ff. 7948aae  Master     -> origin/master
already up-to-date.

This is a complete CI system process, the rest of the most important is how to use, real use.

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.