GitLab是一个代码仓库,用来管理代码。Jenkins是一个自动化服务器,可以运行各种自动化构建、测试或部署任务。所以这两者结合起来,就可以实现开发者提交代码到GitLab,Jenkins以一定频率自动运行测试、构建和部署的任务,帮组开发团队更高效的集成和发布代码
一、实验环境
本文将在单机上搭建一个GitLab+Jenkins环境,两者分别使用不同的端口,操作系统是rhel7.3
安装部署Gitlab服务器
[root@vm2 ~]# yum install -y curl postfix policycoreutils-python openssh-server
[root@vm2 mnt]# yum install gitlab-ce-11.0.1-ce.0.el6.x86_64.rpm -y
更改GitLab URL为本机IP
##修改gitlab仓库路径
[root@vm2 mnt]# vim /etc/gitlab/gitlab.rb
external_url 'http://172.25.18.2'
编译并启动
[root@vm2 mnt]# gitlab-ctl reconfigure
# 重载服务
[root@vm2 mnt]# gitlab-ctl restart
在浏览器输入IP访问,显示GitLab登录界面。
第一次登录需要密码,默认帐号为root,密码设置不低于8位。
两种上传项目的方式,http和ssh,由于http需要每次输入用户账户和密码,较为繁琐。所以,这里采用ssh与gitlab建立连接。
首先,在项目所在主机生成ssh-key。
新建项目
上传项目:
将公钥保存到Gitlab的用户SSH 密钥管理中。
[root@79 test]# echo “test” > test.sh
[root@79 test]# git init
[root@79 test]# git config --global user.name "Vincent"
[root@79 test]# git config --global user.email "westos@org"
Initialized empty Git repository in /mnt/test/.git/
[root@79 test]# git add test.sh
[root@79 test]# git commit -m “test.sh”
[root@79 test]# git remote add origin git@172.25.79.11:root/test.git
[root@79 test]# git push -u origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 221 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@172.25.79.11:root/test.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
上传成功:
安装Jenkins
[root@vm2mnt]#yuminstalljdk-8u171-linux-x64.rpm-y
配置环境变量
[root@vm2~]#echo'exportJAVA_HOME=/usr/java/jdk1.8.0_151/'>>/etc/profile
[root@vm2~]#echo'exportJRE_HOME=/usr/java/jdk1.8.0_151/jre'>>/etc/profile
[root@vm2~]#echo'PATH=$JAVA_HOME/bin:$PATH'>>/etc/profile
[root@vm2~]#tail-3/etc/profile
exportJAVA_HOME=/usr/java/jdk1.8.0_151/
exportJRE_HOME=/usr/java/jdk1.8.0_151/jre
PATH=$JAVA_HOME/bin:$PATH
[root@vm2~]#source/etc/profile
查看版本
[root@vm2~]#java-version
javaversion"1.8.0_171"
Java(TM)SERuntimeEnvironment(build1.8.0_171-b11)
JavaHotSpot(TM)64-BitServerVM(build25.171-b11,mixedmode)
[root@vm2mnt]#yum install jenkins-2.121.1-1.1.noarch.rpm -y
[root@vm2mnt]#/etc/init.d/jenkins restart
Restartingjenkins(viasystemctl):[OK]
[root@vm2mnt]#cat /var/lib/jenkins/secrets/initialAdminPassword
e4dd11a4debd423c9a8318b825bb66b0
在浏览器中访问:http://172.25.79.2:8090
上传项目:
git config --global user.name "Vincent"
git config --global user.email "westos@org.com"
git init
git commit -m "first commit"
git remote add origin git@github.com:J-Vincent/test.git
git push -u origin master