如何搭建一個gitlab ci服務(wù)器,首先解釋下為什么選擇了gitlab ci沒有選擇jeakins
1.個人原因,jeakins 網(wǎng)上到處都是資料,懟gitlab ci更加熟悉。
2.gitlab和gitlab之前集成非常好的,這是不用質(zhì)疑的。
3. 介紹下gitlab ci,不弱于jeakins,很多方面比jeakins對gitlab集成更強大。
# -*- mode: ruby -*-# vi: set ft=ruby :Vagrant.require_version ">= 1.6.0"boxes = [ { :name => "gitlab-ci", :mem => "4096", :cpu => "2" }]Vagrant.configure(2) do |config| config.vm.box = "centos/7" boxes.each do |opts| config.vm.define opts[:name] do |config| config.vm.hostname = opts[:name] config.vm.provider "vmware_fusion" do |v| v.vmx["memsize"] = opts[:mem] v.vmx["numvcpus"] = opts[:cpu] end config.vm.provider "virtualbox" do |v| v.customize ["modifyvm", :id, "--memory", opts[:mem]] v.customize ["modifyvm", :id, "--cpus", opts[:cpu]] end config.vm.network :private_network, type: "dhcp" end end config.vm.provision "shell", privileged: true, path: "./setup.sh"end
#/bin/shsudo yum install -y yum upgradesudo yum install -y net-toolssudo yum install -y curl policycoreutils openssh-server openssh-clientssudo systemctl enable sshdsudo systemctl start sshdsudo yum install -y postfixsudo systemctl enable postfixsudo systemctl start postfixsudo firewall-cmd --permanent --add-service=httpsudo systemctl reload firewalldsudo curl -sSL https://get.docker.com/ | sh
#源碼No.11的gitlab-ci目錄vagrant up
新建 gitlab-ci-multi-runner.repo
sudo touch /etc/yum.repos.d/gitlab-ci-multi-runner.reposudo vi /etc/yum.repos.d/gitlab-ci-multi-runner.repo
將以下內(nèi)容寫入文件
[gitlab-ci-multi-runner]name=gitlab-ci-multi-runnerbaseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ci-multi-runner/yum/el7repo_gpgcheck=0gpgcheck=0enabled=1gpgkey=https://packages.gitlab.com/gpg.key
執(zhí)行
sudo yum makecachesudo yum install gitlab-ci-multi-runner
查詢運行狀態(tài)
sudo gitlab-ci-multi-runner status
設(shè)置docker權(quán)限
為了能讓gitlab-runner能正確的執(zhí)行docker的命令,需要把gitlab-runner添加到docker group里,然后重啟docker 和 gitlab-runner
sudo usermod -aG docker gitlab-runnersudo service docker restartsudo gitlab-ci-multi-runner restart
http://172.28.128.3/
i_qDxLL_yQTzMuSR1-6J
#自己起個名字方便區(qū)別test1
#自己起個標簽方便區(qū)別test1
#直接回車
#直接回車
shell
stages: - test - build - deployjob1: stage: test tags: - test1 script: - echo "個人網(wǎng)站:idig8.com" - echo "個人公眾號:編程坑太多" - echo "--------job1----------"job2: stage: build tags: - test1 script: - echo "個人網(wǎng)站:idig8.com" - echo "個人公眾號:編程坑太多" - echo "--------job2----------"job3: stage: deploy tags: - test1 script: - echo "個人網(wǎng)站:idig8.com" - echo "個人公眾號:編程坑太多" - echo "--------job3----------"
查看失敗原因
#原來是域名的問題,開始修改。Running with gitlab-ci-multi-runner 9.5.1 (96b34cc) on gitlab-ci (4d12d67f)Using Shell executor...Running on gitlab-ci...Cloning repository...Cloning into '/home/gitlab-runner/builds/4d12d67f/0/root/test1'...fatal: unable to access 'http://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@gitlab.example.com/root/test1.git/': Could not resolve host: gitlab.example.com; Unknown errorERROR: Job failed: exit status 1
sudo vi /etc/hosts # 添加 172.28.128.3 gitlab.example.com
PS:整個這個功能是否給你一個很大的想象空間,任何的軟件的項目,可以通過ci-Pipelines方式,來定義自己的Pipelines,在測試,部署。很大很的發(fā)揮空間。都可以通過自定yml文件來實現(xiàn)。
>>原創(chuàng)文章,歡迎轉(zhuǎn)載。轉(zhuǎn)載請注明:轉(zhuǎn)載自IT人故事會,謝謝!聯(lián)系客服