GitLab+Jenkins部署及实现集成
GitLab介绍GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的web服务。
系统环境准备
建议:内存4G以上不然带不动
1234# cat /etc/redhat-releaseCentOS Linux># uname -r3.10.0-693.el7.x86_64 #关闭firewalld和NetWorkManager
12# systemctl stop firewalld# systemctl stop NetWorkManager #永久关闭
12# systemctl disable firewalld# systemctl disable NetWorkManager #关闭selinux
12# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config# setenforce 0 #更换阿里源和下载epel源
123#mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup#wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo#wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo #yum源更新,重启系统
1# yum update && reboot #安装相应工具
12yum install curl policycoreutils openssh-server openssh-clients postfix -ysystemctl start postfix #新建GitLab源
12345678910# vim /etc/yum.repos.d/gitlab-ce.reponame=gitlab-cebaseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7repo_gpgcheck=0gpgcheck=0enabled=1gpgkey=https://packages.gitlab.com/gpg.key# yum makecache# yum install -y gitlab-ce #安装git工具
1# yum install git -y #加载配置文件并启动,时间稍长
1# gitlab-ctl reconfigure #gitlab-ctl其他命令
12345启动:gitlib-ctl start关闭:gitlab-ctl stop重启:gitlab-ctl restart重载配置:gitlab-ctl reconfigure查看状态:gitlab-ctl status #查看端口保证80端口不被占用
1234# lsof -i:80COMMAND PID USER FD TYPE DEVICE>nginx 700 root 7uIPv416903 0t0TCP *:http (LISTEN)nginx 804 gitlab-www 7uIPv416903 0t0TCP *:http (LISTEN) #gitlab配置文件路径
1/etc/gitlab/gitlab.rb 浏览器登录gitlab,输入http://ip进入下图:
https://images2018.cnblogs.com/blog/1271786/201803/1271786-20180328155736573-695667085.png
先输入密码,然后Register填写账户信息进入新建项目
https://images2018.cnblogs.com/blog/1271786/201803/1271786-20180328160016623-145666876.png
填写ssh认证
https://images2018.cnblogs.com/blog/1271786/201803/1271786-20180328160211169-1446140189.png
测试拉取代码
12345678910# git clone git@hejianlai-jenkins:web/web-demo.gitCloning into 'web-demo'...remote: Counting objects: 6, done.remote: Compressing objects: 100% (3/3), done.remote: Total 6 (delta 0), reused 0 (delta 0)Receiving objects: 100% (6/6), done.# lsanaconda-ks.cfgepel-release-latest-7.noarch.rpmweb-demo# ls web-demo/index.htmlREADME.md 上传代码
12345678910111213141516171819202122232425262728293031# echo "test" >>test.txt # git config --global user.email "you@example.com"# git config --global user.name "Your Name"# git add *# git commit -m "add test.txt" add test.txt 1 file changed, 1 insertion(+) create mode 100644 test.txt# git pushwarning: push.default is unset; its implicit value is changing inGit 2.0 from 'matching' to 'simple'. To squelch this messageand maintain the current behavior after the default changes, use: git config --global push.default matching To squelch this message and adopt the new behavior now, use: git config --global push.default simple See 'git help config' and search for 'push.default' for further information.(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode'current' instead of 'simple' if you sometimes use older versions of Git) Counting objects: 4, done.Delta compression using up to 2 threads.Compressing objects: 100% (2/2), done.Writing objects: 100% (3/3), 314 bytes | 0 bytes/s, done.Total 3 (delta 0), reused 0 (delta 0)To git@hejianlai-jenkins:web/web-demo.git 18a57cf..5df66f7master -> master GitLab上查看:
https://images2018.cnblogs.com/blog/1271786/201803/1271786-20180328160927691-662501372.png
#安装JenKins
123456789# sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo # sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key# yum install java jenkins –y#JenKins默认端口为8080,因为gitlab已经占用我们需要更改。 # vim /etc/sysconfig/jenkins JENKINS_PORT="8080"---> JENKINS_PORT="8081" #启动JenKins
12# /etc/init.d/jenkins startStarting jenkins (via systemctl): #浏览器登录JenKins,地址:http://192.168.247.135:8081/
正在启动;
https://images2018.cnblogs.com/blog/1271786/201803/1271786-20180328150015538-1428341532.png
进入有个密码路径,系统上查看这个文件并把密码复制粘贴才能登录;
https://images2018.cnblogs.com/blog/1271786/201803/1271786-20180328150200838-416622945.png
https://images2018.cnblogs.com/blog/1271786/201803/1271786-20180328150244197-210677821.png
选择推荐安装;
https://images2018.cnblogs.com/blog/1271786/201803/1271786-20180328150408289-482385642.png
创建一个管理员
https://images2018.cnblogs.com/blog/1271786/201803/1271786-20180328151718642-576724807.png
开始使用jenkins
https://images2018.cnblogs.com/blog/1271786/201803/1271786-20180328151802968-1171048845.png
下面实现持续集成
进入主页--创建一个新任务
https://images2018.cnblogs.com/blog/1271786/201803/1271786-20180328152125270-31472436.png
输入项目名称---构建一个自由风格的软件项目---确认
https://images2018.cnblogs.com/blog/1271786/201803/1271786-20180328152325544-1437452721.png
General--填写项目描述
https://images2018.cnblogs.com/blog/1271786/201803/1271786-20180328152534417-1415924188.png
源码管理--安装git插件--授权认证
https://images2018.cnblogs.com/blog/1271786/201803/1271786-20180328153033960-396818775.png
ssh私钥认证我们在系统上查看粘贴进去即可。
https://images2018.cnblogs.com/blog/1271786/201803/1271786-20180328153936242-1719394230.png
https://images2018.cnblogs.com/blog/1271786/201803/1271786-20180328154109302-1300647725.png
Credentials—选择root
https://images2018.cnblogs.com/blog/1271786/201803/1271786-20180328154216034-1143683245.png
查看gitlab版本
12# rpm -aq|grep gitlabgitlab-ce-10.6.0-ce.0.el7.x86_64https://images2018.cnblogs.com/blog/1271786/201803/1271786-20180328154637395-1983941477.png
点击立即构建
https://images2018.cnblogs.com/blog/1271786/201803/1271786-20180328154724955-1894082618.png
点击控制台输出查看
https://images2018.cnblogs.com/blog/1271786/201803/1271786-20180328154830061-1138618227.png
控制台输出,SUCCESS则构建成功
https://images2018.cnblogs.com/blog/1271786/201803/1271786-20180328154912495-206%C3%97%C3%97%C3%97122.png
转载地址:https://www.cnblogs.com/Dev0ps/p/8663262.html
页:
[1]