【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 @   代码诠释的世界  阅读(616)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示