【ubuntu 18.04】gitlab配置gitlab-runner,实现CI/CD

1. 下载gitlab-runner

Download and install binary
# Download the binary for your system
sudo curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64

2. 安装

# Give it permissions to execute
sudo chmod +x /usr/local/bin/gitlab-runner

# Create a GitLab CI user
sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash

# Install and run as service
sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
sudo gitlab-runner start

3. 注册runner

Command to register runner
sudo gitlab-runner register --url http://192.168.10.99/ --registration-token $REGISTRATION_TOKEN

信息获取

 

 注册流程

master@master:~/spring-boot-demo$ sudo gitlab-runner register --url http://192.168.10.99/ --registration-token avMBwSLHcaYAQzBHpMcj
Running in system-mode.

Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
[http://192.168.10.99/]:
Please enter the gitlab-ci token for this runner:
[avMBwSLHcaYAQzBHpMcj]:
Please enter the gitlab-ci description for this runner:
[master]:
Please enter the gitlab-ci tags for this runner (comma separated):
java
Whether to run untagged builds [true/false]:
[false]: true
Whether to lock the Runner to current project [true/false]:
[true]:
Registering runner... succeeded                     runner=avMBwSLH
Please enter the executor: docker-ssh+machine, kubernetes, parallels, shell, ssh, virtualbox, docker+machine, docker, docker-ssh:
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

注册成功

 

4. 编写.gitlab.yml文件

 

 文件内容

stages:
  - install_deps
  - test
  - build
  - deploy_test
  - deploy_production

cache:
  key: ${CI_BUILD_REF_NAME}
  paths:
    - ./

install_deps:
  stage: install_deps
  only:
    - master
  script:
    - echo install_deps


test:
  stage: test
  script:
    - mvn verify
  artifacts:
    when: always
    reports:
      junit:
        - target/surefire-reports/TEST-*.xml
        - target/failsafe-reports/TEST-*.xml

build:
  stage: build
  only:
    - master
  script:
    - mvn clean package -DskipTests

deploy_test:
  stage: deploy_test
  only:
    - master
  script:
    - echo test    

deploy_production:
  stage: deploy_production
  only:
    - master
  script:
    - echo deploy_production

5. 测试结果(提交代码到仓库)

 

 查看每个job执行情况

 

Test的job日志

 

 基本完成

 

posted @ 2021-12-21 17:56  代码诠释的世界  阅读(585)  评论(0编辑  收藏  举报