Continuous Integration

2016-08-26 14:31:19来源:oschina作者:pillsilly人点击

-- 几个月前的学习笔记,懒得再翻译回来了

Continuous Integration

Continuous Integration
Purpose & Main Goals
Enviroment Infomation
Configuring Env Path
Installing JDK 1.8
Install Nexus
Configuring iptables
Verify Nexus service by setting up a Maven project
Install Maven on server side (later will be used by Jenkins)
Install GitLab
Enable SSH connection using GitLab without password
Install Jenkins
Setup automated build in Jenkins with Gitlab’s Web Hook feature
Setup automated deploy after build in Jenkins
Install Git server(Optional)
Purpose & Main Goals

Automatically build

Expose problems earlier.

Common module management.

Internal Maven Server makes building process faster.

Set up the standard of the whole life circle of Soft Ware development.

Code Review Process setup

Build trigger

Automatically deploy

Automatically test run : (Front end and Back End (Unit Test Framework integration))

base platforms setupgitlab , nexus,jenkins , maven

Enviroment Infomation

CentOS root @ qazwsx%1984416ssh work dir :/home/soft

Configuring Env Path

open/etc/profile,add below text to the end

export PATHInstalling JDK 1.8

rpm -ivhjdk-8u65-linux-x64.rpm Install Nexus

in this case , we use the nexus 2 because it’s more friendly with maven then nexus 31

tar -xvfnexus-latest-bundle.tar.gz
run/home/soft/nexus-extract/nexus-2.13.0-01/bin/nexus - default account : admin/admin123

Configuring iptables

vi /etc/sysconfig/iptables

add this to the end :-A INPUT -p tcp -m sate --state NEW -m tcp --dport 8081 -j ACCEPT

or ,simply turn off the iptable service byservice iptables stop

Verify Nexus service by setting up a Maven project

In project’s pom.xml,add this(it tells maven which repository to deploy the jar):


In maven’s setting.xml (pls usemvn help:effective-settingsto ensure that which file is currently effective)


Install Maven on server side (later will be used by Jenkins)

tar -xvfapache-maven-3.3.9-bin.tar.gz Install GitLab

Official Installation Guide :
If you’re in CentOS 6/7 , to avoid from the network connectivity problem in China, I suggest you use the rpm way. in my case : I usegitlab-ce-8.8.5-ce.1.el6.x86_64.rpm
install path would be :/var/opt/gitlab
default repository is/var/opt/gitlab/git-data
setting file is :/etc/gitlab/gitlab.rb
Usegitlab-ctlto manage the application (start,stop,tail,etc)
Problems occured solved:

Port in use ? Because the component “Tweak” using 8080 as the default port,if it’s been taken by any other program,GitLab would be failed to start.

To change the port

vi /etc/gitlab/gitlab.rb
Find session # GitLab Unicorn #
Modifyunicorn['listen'] = '',unicorn['port'] = 8090
Apply changes :sudo gitlab-ctl reconfigure
Check logssudo gitlab-ctl tail
Set git user’s default shell to bash :usermod -s /bin/bash git

Default Account ?

During the installing process,you’d be asked to set your password,it means your current Linux account ,e.groot;After installation has been done,you can use that to login into the system.
If there’s no account/pwd setting process came out during the installation,you can register one from the entry index,and it’d be the admin authority.

Enable SSH connection using GitLab without password

Use Git Bash as the Git Client in Windows.
Open GitBash from user home dir : e.gC:/Users/bob/.ssh>

Execute command :ssh-keygen -t rsa

type %userprofile%/.ssh/ | clip

Go to GitLab User Profile Page,add a SSH Key like below (the key’s already in your clip)

About ssh no-pwd verify login: After your execute the commandssh-keygen -t rsa The generated 3 files : id_rsa, , known hosts are bound together on the client side ,and it must be under client side’s user folder (in this case :C:/Users/bob/.ssh). After you gave out the public keyid_rsa.pubto the server side , where did it go? it’s been added to the end of the file of/var/opt/gitlab/.ssh/authorized_keyson the server side

Install Jenkins

Download latest Jenkinshere
Start it with executingnohup java -jar jenkins.war &. Or you can deploy it into tomcat , which is more recommended.
Install git plugin from system admin page.
To add Credential,here are the steps:

Supposed I’m trying to add a project and my git accont is bob
Login as bob in git server
ssh-keygen -t rsapress ENTER till it’s done.*(this will gen 2 files “id_rsa”,”” under default user home “/home/bob/.ssh”,cat id_rsaand you’ll see the private key content )
go to the jenkins admin page : index->Credentials->System->Goblal credentials->Add Credentials
Kind: SSH
Scope: Global
Username : your git username(linux account)
Private Key : Enter directly (step 3)
other field just leave for emptytry a maven@git project build with jenkins

index -> new
choose maven,next
choose git and give the git url
choose the credential that you just created. save
click build on the left side Setup automated build in Jenkins with Gitlab’s Web Hook feature


go to Settings > Webhooks
at “URL” fill in withhttp://
at “Trigger” choose whenever you want it to be triggered.


Install pluginGitlab Hook Pluginon Jenkins ,seeUsage

配置 –> Gitlab Web Hook check the option :Trigger build also when pushing to merged branches

Project Configuration

参数化构建过程,do as follow ;

go toBranches to buildfill in with$BRANCH_TO_BUILD

go to source browser,do as follow
Setup automated deploy after build in Jenkins

InstallDeploy to container Plugin
Do as follow

enable tomcat manage console

configure theconf/tomcat-users.xml

tomcat/tomcatwould be the user Jenkins’d use.

Install Git server(Optional)

install neccesary dependence

yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel some times the zlib env might go wrong ,try download and make install
other dependence error pls ref to thislink

install git

get latest git source packagehere
tar -zxvf git-2.9.0.tar.gz
cd git2.9
make install
git version

add git accounts on server side

add a user :useradd -g git git
set password for it :passwd git
delete a user (-fmeans also delete user’s folder)userdel -f git

create a test repository directory

mkdir /home/soft/git/repo1
initial :git init --bare project.git

grand authority

sudo chown -R git:git project.git

ssh setting (client side)

ssh-keygen -t rsa
scp ~/.ssh/ root@

or you can pass your rsa key in text ,after key generating,docat rsa.puband you’ll see the rsa key content, pass it to server admin,and he shall write that into/home/git/.ssh/authorized_keys(real path might depends)

verify uploaded file(server side):ls ~/

try it on client side

mkdir testrepo1
cd testrepo1
git clone git@