Last Updated: May 27, 2017
·
631
· CCalorie

GitLab CI

1. GitLab CI 与 GitLab Runner简述

Getting started with GitLab CI (https://docs.gitlab.com/ee/ci/quick_start/README.html)
GitLab Runner (https://gitlab.com/gitlab-org/gitlab-ci-multi-runner)

2. 下载并安装GitLab Runner

安装方式可以分为两种:通过二进制文件安装和Docker安装

最简单直接的方式是通过Homebrew进行下载安装 brew install gitlab-ci-multi-runner,执行成功后直接跳到下一步就行了

但如果公司的GitLab版本与Runner版本不兼容,则报错 GitLab Runner >= 9.0 can be used ONLY with GitLab CE/EE >= 9.0

解决方法一:Homebrew下载指定版本的gitlab-ci-multi-runner,但并没有找到怎么安装指定版本模块的brew命令

解决方法二:手动安装指定版本

下载 binaries/gitlab-ci-multi-runner-darwin-amd64 (https://gitlab-ci-multi-runner-downloads.s3.amazonaws.com/v1.11.2/index.html)

然后执行命令

cp gitlab-ci-multi-runner-darwin-amd64 /usr/local/bin/gitlab-ci-multi-runner

chmod +x /usr/local/bin/gitlab-ci-multi-runner

拷贝 gitlab-ci-multi-runner-darwin-amd64 到bin命令目录,并赋予 gitlab-ci-multi-runner 可执行权限.

3. 绑定GitLab CI,注册GitLab Runner

访问项目配置页面

Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):

http://gitlab.bojoy.net:9090/ci

Please enter the gitlab-ci token for this runner:

57WDUuxZRpiVbTYW_AFd

Please enter the gitlab-ci description for this runner:

[hwy-app15deiMac.local]: GitLabRunner

Please enter the gitlab-ci tags for this runner (comma separated):

calorie

Whether to run untagged builds [true/false]:

[false]: true

Registering runner... succeeded                     runner=57WDUuxZ

Please enter the executor: shell, docker+machine, docker-ssh, parallels, ssh, virtualbox, docker-ssh+machine, kubernetes, docker:

shell

Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

配置信息说明

  • 输入项目GitLab CI的URL
  • 输入项目GitLab CI的token
  • 输入项目GitLab Runner的description
  • 输入项目GitLab Runner的tags (在项目构建流程yaml文件里面指定tag,就是匹配使用哪个tag的runner!)
  • 是否运行未加标签的构建, true/false
  • 执行者,一般选shell或docker
  • Runner注册成功!

若注册成功,在项目配置Runner中则可以看到刚注册的Runner信息

  1. 启动GitLab Runner

gitlab-ci-multi-runner install

gitlab-ci-multi-runner start

gitlab-ci-multi-runner run

  1. 定义项目构建流程

根目录创建 .gitlab-ci.yml 文件,iOS 模板

Configuration of your jobs with .gitlab-ci.yml (https://docs.gitlab.com/ee/ci/yaml/README.html)

This file is a template, and might need editing before it works on your project.

Lifted from: https://about.gitlab.com/2016/03/10/setting-up-gitlab-ci-for-ios-projects/

This file assumes an own GitLab CI runner, setup on an OS X system.

stages:

 - build

 - archive

build_project:

 stage: build

 script:

   - xcodebuild clean -project ProjectName.xcodeproj -scheme SchemeName | xcpretty

   - xcodebuild test -project ProjectName.xcodeproj -scheme SchemeName -destination 'platform=iOS Simulator,name=iPhone 6s,OS=9.2' | xcpretty -s

 tags:

   - ios_9-2

   - xcode_7-2

   - osx_10-11

archive_project:

 stage: archive

 script:

   - xcodebuild clean archive -archivePath build/ProjectName -scheme SchemeName

   - xcodebuild -exportArchive -exportFormat ipa -archivePath "build/ProjectName.xcarchive" -exportPath "build/ProjectName.ipa" -exportProvisioningProfile "ProvisioningProfileName"

 only:

   - master

 artifacts:

   paths:

   - build/ProjectName.ipa

 tags:

   - ios_9-2

   - xcode_7-2

   - osx_10-11

注意:

你必须确保熟悉 xcodebuild 命令;

tags 为之前注册GitLab Runner的 tags;

编译 Scheme 需勾选 Shared.

构建效果

引用:

持续集成 (http://baike.baidu.com/item/持续集成)

GitLab-CI与GitLab-Runner (http://www.jianshu.com/p/2b43151fb92e)

Docker搭建自己的Gitlab CI Runner (http://blog.csdn.net/aixiaoyang168/article/details/72168834)

用 GitLab CI 进行持续集成 (https://segmentfault.com/a/1190000006120164)