GitLab-Runner安装及使用

Git_Lab CI Setting

  1. 根据该教程本地下载并安装 gitlab-runner.exe

  2. 在GitLab远程仓库页面点击 setting-> CI/CD ->runner Expand ,然后拷贝 Runner setup URL , registration token到第三步输入

  3. install gitlab-runner.exe and register on local PC

    # at the git runner folder
    gitlab-runner.exe install
    gitlab-runner.exe register
       ...enter Runner setup URL
       ...enter registration token
       ...enter runner description
       ...enter runner tag (Unique Identification)
       ...enter script executor(depend on script language)
    ## automatically generate config.toml after success
  4. 修改runner中对应的config.toml

concurrent = 1
check_interval = 0
​
[session_server]
  session_timeout = 1800
​
[[runners]]
  name = " PC_1"
  url = "https://gitlab.test.com/"
  token = "test123456789"
  executor = "shell"
  builds_dir = "E:\\GitLab-Runner\\builds"
  cache_dir = "E:\\GitLab-Runner\\cache"
  environment = ["SCE_PHYRE=E:\\GitLab-Runner\\builds\\test"] #设置runner无法读取的环境变量
  shell = "powershell"  # 配置gitlab-ci.yml script会使用的语言 runner为win系统时建议使用powershell
  [runners.custom_build_dir]
    enabled = true # 自定义runner本地存储代码的位置
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
  1. 在远程仓库根目录下创建t gitlab-ci.yml 文件

#ex:
compile:
  script:
    - cd /d "D:\test"  # 执行runner命令,自定义
    - echo test
  tags:
    - PC_1 # 选择“gitlab-runner.exe register”中设置的“runner tag”
  variables: 
    GIT_CLEAN_FLAGS: -ffdx -e cache/ # 清空缓存
    GIT_CLONE_PATH: $CI_BUILDS_DIR/$CI_PROJECT_NAME # 设置仓库下载地址
  1. 配置成功后在本地目录下启动runner

    gitlab-runner.exe run --syslog # 不可关闭当前terminal

注:

  • 修改config.toml、注册runner,需要关闭“gitlab-runner.exe run --syslog”(在当前终端Ctrl+C)

  • 一个gitlab-runner.exe可注册多个项目的runner,但不能过多, 同一台主机可以存在多个gitlab-runner.exe(不同目录,仓库地址也不能冲突)

  • config.toml中的“\”需要使用“\\

CMD

gitlab-runner.exe install
gitlab-runner.exe register
gitlab-runner.exe start
gitlab-runner.exe restart
gitlab-runner.exe stop
​
gitlab-runner.exe run --syslog
​
ssh-keygen -t rsa -C xxx@xxx.com.cn  # 

.gitlab-ci.yml (Git_lab Code)

# 定义 stages
stages:
    - test 
    - compile
test:
    stage: test
    script:
        - echo test
    tags:
        - PC_1  
    
deploy:
    stage: compile
    script:
        - cd /d "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE"
        - devenv.com "E:\GitLab-Runner\builds\test\test.sln" /rebuild "Release|x64"
    tags:
        - PC_1      
variables: 
    GIT_CLEAN_FLAGS: -ffdx -e cache/ # clear git code
    GIT_CLONE_PATH: $CI_BUILDS_DIR/$CI_PROJECT_NAME   # code dir

QA:

删除register
  1. 在gitlab->setting->ci->runner->expand 删除对应runner

  2. 删除runner本地config.toml文件的对应runner配置

posted @ 2020-01-13 15:50  Stranger115  阅读(1068)  评论(0编辑  收藏  举报