GitLab Continuous Integration(CI) -1

GitLab Continuous Integration(CI)

If you add a .gitlab-ci.yml file to the root directory of your repository, and configure your Gitlab project to use a Runner, then each merge request or push trigger your CI pipeline.

The .gitlab-ci.yml file tells the Gitlab runner what to do. By default it runs a pipeline with threes stages: build, test, and deploy. You don’t need to use all three stages; stages with no jobs are simply ignored.

If everything runs ok (no non-zero return values), you will get a nice green checkmark associated with the pushed commit or merge request.

Most projects use Gitlab’s CI service to run the test suite so that developers get immediate feedback if they broken something.

There’s growing trend to use continuous delivery and continuous deployment to automatically deploy tested code to staging and production environments.

so in brief, the steps needed to have a working CI can be summed up to:

Add .gitlab-ci.yml to the root directory of your repository
Configure a Runner

From there on, on every push to your Git resposity, the Runner will automagically start the pipeline and the pipeline will appear under there projects’ /pipelines page.

This guide assumes that you:

have a working Gitlab instance of version 8.0 or higher or are using GitLab.com
have a project in gitLab that you would like to use CI for

Let’s break it down to pieces and work on solving the GitLab CI puzzle.

Creating a .gitlab-ci.yml file

What is .gitlab-ci.yml

The .gitlab-ci.yml file is where you configure what CI does with your project. It lives in the root of your repository.
On any push to your repository, GitLab will look for the .gitlab-ci.yml file and start builds on Runners according to the contents of the file, for that commit.

Because .gitlab-ci.yml is in the repository and is version controlled, old versions still build successfully, forks can easily make use of CI, branches can have different pipelines and jobs, and you have a single source of truth for CI.

Note: .gitlab-ci.yml is a YAML file so you have pay extra attention to indentation. Always use spaces, not tabs.

If you want to check whether your .gitlab-ci.yml file is valid, there is a Lint tool under the page ?ci/lint of your GitLab instance. You can also find there link under Settings > CI settings in your project.

For more information and a complete .gitlab-ci.yml syntax, please read http://doc.gitlab.com/ce/ci/yaml/README.html

Push .gitlab-ci.yml to GitLab

Once you’ve created .gitlab-ci.yml, you should add it to your repository and push it to GitLab.

git add .gitlab-ci.yml
git commit -m “Add .gitlab-ci.yml”
git push origin master

Now if you go to the Pipelines page you will see that pipeline is pending.

You can also go to the Commits page and notice the little clock icon next to the commit SHA.

Clicking on the rock you will be directed to the builds page for that specific commit.

Notice that there are two jobs pending which are named after what we wrote in .gitlab-ci.yml. The red triangle indicates that there is no Runner configured yet for these builds.

The next step is to configure a Runner so that it picks the pending builds.

In GitLab, Runners run the builds that you define in .gitlab-ci.yml. A Runner can be a virtual machine, a VPS, a bare-metal machine, a docker container or even a cluster of containers. GitLad and the Runners communicate through an API, so the only requirement is that the Runner’s machine has Internet access.

A Runner can be specific to a certain project or serve multiple projects in GitLab. If ti serves all projects it’s called a Shared Runner.

Find more information about Runner from this link : http://doc.gitlab.com/ce/ci/runners/README.html

#Install gitlab-ci-multi-runner#

GitLab Continuous Integration Server

ssh gci.xq.cn -l james

Install Docker runner:

curl -sSL https://get.docker.com/ | sh

Error reporting -
curl: (6) Could not resolve host: get.docker.com; Unknown error

cat /etc/resolv.conf

Generated by NetworkManager

search xq.cn

No nameservers found; try putting DNS servers into your

ifcfg files in /etc/sysconfig/network-scripts like so:

DNS1=xxx.xxx.xxx.xxx

DNS2=xxx.xxx.xxx.xxx

DOMAIN=lab.foo.com bar.foo.com

Add nameserver 8.8.8.8 to resolv.conf

Execute : curl -sSL https://get.docker.com/ | sh

Ok. Done.

curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-ci-multi-runner/script.rpm.sh | sudo bash
sudo wget -O /usr/local/bin/gitlab-ci-multi-runner https://gitlab-ci-multi-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-ci-multi-runner-linux-386

创建一个项目,并查看项目的 Runner
创建项目 -》 Setting -》Runner

Specific runners
How to setup a new project specific runner
Install GitLab Runner software. Checkout the GitLab Runner section to install it
Specify following URL during runner setup: http://git.xq.cn/ci
Use the following registration token during setup: St8Crygwy6sc75jqqw-y
Start runner!

使用 Runner

在项目根目录下,创建 .gitlab-ci.yml
内容如下:

before_script:

  • sudo composer global require "laravel/installer"

init_jog:
script:

  • touch test.php
    在执行脚本之前,先去安装 laravel 框架。然后,再去执行工作 init_jog,这个工作也就是简单创建一个 test.php 脚本 。

git push origin master 之后,

到 GitLab 项目管理页面,查看 “Builds” ,

如何检查 yml 文件的语法

http://git.xq.cn/ci/lint

GitLab CI Issues


Build always pending
Summary: GitLab CI does not start building of jobs, it is always pending.
Steps to reproduce: Install GitLab CI 7-10-stable, add a runner, add a repo, commit to the repo
Expected behavior: GitLab CI should trigger the runner and the runner should start to build
Observed behavior GitLab CI recognizes the commit and says build is pending, but does not trigger the runner. It says, that the last contact to the runner was never.
Relevant logs and/or screenshots: Every 5 Seconds in production.log: Started POST "/api/v1/builds/register.json" for 127.0.0.1 at 2015-04-27 05:08:48 +0200

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 206,723评论 6 481
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 88,485评论 2 382
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 152,998评论 0 344
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 55,323评论 1 279
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 64,355评论 5 374
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,079评论 1 285
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,389评论 3 400
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,019评论 0 259
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,519评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,971评论 2 325
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,100评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,738评论 4 324
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,293评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,289评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,517评论 1 262
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,547评论 2 354
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,834评论 2 345

推荐阅读更多精彩内容