gitlab-ci

作者: drawing818 | 来源:发表于2020-02-15 21:27 被阅读0次

GitLab CI/CD

GitLab提供了持续集成服务,对于每次提交或推送以触发您的CI管道,您必须:

  • 将.gitlab-ci.yml文件添加到存储库的根目录中
  • 确保将项目配置为使用Runner

安装 Runner

https://packages.gitlab.com/runner/gitlab-runner?page=3
根据自己的系统,选择Debian或者rpm类型安装包
例如,CentOS系统,就选择rpm,执行

curl -s https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash
yum install gitlab-runner

配置 Runner

1.执行下列命令

sudo gitlab-runner register

2.输入 GitLab 实例 URL:

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

3.输入项目token(可以在Settings->CI/CD->Runners中获取):

Please enter the gitlab-ci token for this runner
xxx
  1. 输入Runner的描述
Please enter the gitlab-ci description for this runner
[hostname] my-runner

5.输入Runner的tag:

Please enter the gitlab-ci tags for this runner (comma separated):
my-tag,another-tag

6.输入Runner executor,一般选择shell就可以:

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

7.如果您选择Docker作为执行程序,系统会要求您提供默认镜像,以用于未在.gitlab-ci.yml中定义的项目中:

Please enter the Docker image (eg. ruby:2.6):
alpine:latest

编写 .gitlab-ci.yml 并提交到根目录下

例如笔者的一个Java项目

stages:
  - prepare
  - compile
  - check
  - package

job1:
  stage: compile
  tags:
    - codecheck
  script:
    - source /etc/profile
    - mvn clean compile -s settings.xml

job2:
  stage: package
  tags:
    - codecheck
  script:
    - source /etc/profile
    - mvn clean package -DskipTests -s settings.xml
 
job3:
  stage: prepare
  tags:
    - codecheck
  script:
    - echo "hello world!"
    - ls -al
    - pwd
    - whoami
    - uname -a
 
chekstyle:
  stage: check
  allow_failure: true
  tags:
    - codecheck
  script:
    - mvn checkstyle:check -s settings.xml

findbugs:
  stage: check
  tags:
    - codecheck
  script:
    - mvn findbugs:check -s settings.xml

pmd:
  stage: check
  tags:
    - codecheck
  script:
    - mvn pmd:check -s settings.xml

执行结果

批注 2020-02-15 212643.jpg

相关文章

网友评论

      本文标题:gitlab-ci

      本文链接:https://www.haomeiwen.com/subject/vnayfhtx.html