• gitlab + gitlab-runner 集成 CICD


    一、gitlab-runner 安装

    1.1 、下载执行文件

    # Linux x86-64
    sudo wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64
    
    # Linux x86
    sudo wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-386
    
    # Linux arm
    sudo wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-arm

    1.2、设置执行权限

    sudo chmod +x /usr/local/bin/gitlab-runner

    1.3 、创建 GitLab CI 用户

    useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash

    1.4、运行服务

    gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
    gitlab-runner start

    二、注册

    2.1 获取 Gitlab 注册令牌,gitlab地址

    打开 gitlab 项目 -> 设置 -> CI / CD -> Runners 设置

    2.2、 LINUX 注册

    • 运行注册
    • sudo gitlab-runner register
    • 输入你的 GitLab URL(上面的gitlab地址

    • Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com )
      http://192.168.182.135:8080/
    • 输入 注册令牌 来注册 Runner(上面的注册令牌

    • Please enter the gitlab-ci token for this runner
      1PyJ-5LsbgN9Qow6MXhN
    • 输入 Runner 说明(任意)

    • Please enter the gitlab-ci description for this runner
      [hostame] my-runner
    • 输入 Runner 的 tags(任意)

    • Please enter the gitlab-ci tags for this runner (comma separated):
      my-tag,another-tag
    • 输入 Runner 执行方式(选择shell方式)

    • Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell:
      shell
    • 如果是在 Docker 中运行, you'll be asked for the default image to be used for projects that do not define one in .gitlab-ci.yml:

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

    三、 链接成功

    四、 编写 .gitlab-ci.yml 集成

    image: java:8
    stages:
      - build
      - build-pro
    
    #测试环境
    build:
      stage: build
      script:
      - pwd
      - cd project/my_app
      - /usr/local/maven/bin/mvn clean package -P test
      - sh /usr/local/project_deploy_script/app/app_test.sh
      tags:
      - deploy-app
      only:
      - develop
    #正式环境
      stage: build-pro
      script:
      - pwd
      - cd project/my_app
      - /usr/local/maven/bin/mvn clean package -P pro
      - sh /usr/local/project_deploy_script/app/app.sh
      tags:
      - deploy-app
      only:
      - master

    五、执行集成

    • 下次提交代码就会走集成任务了

  • 相关阅读:
    redis在实践中的一些常见问题以及优化思路(包含linux内核参数优化)
    分库分表基本概念
    产品经理黑话
    在linux虚拟机中安装部署MySQL数据库
    计算机专业本科自考
    在项目中重新搭建一套读写分离+高可用+多master的redis cluster集群
    扔掉工具类,Mybatis一个简单配置搞定数据加密解密!
    两台Linux系统之间传输文件使用scp的解决方案
    博客园积分排名前3000名
    内网穿透在家远程连接公司电脑<强烈收藏,早晚用得上>
  • 原文地址:https://www.cnblogs.com/liugp/p/12181384.html
Copyright © 2020-2023  润新知