美文网首页CI-Gitlab
Gitlab-Runner-Shell

Gitlab-Runner-Shell

作者: 偏分武士 | 来源:发表于2019-06-11 17:20 被阅读0次

Runner支持运行在windows/mac/linux环境下

这里以在windows环境下安装runner为例

一、下载Runner

runner主页:

https://about.gitlab.com/product/continuous-integration/#gitlab-runner

runner下载:

1. 打开https://docs.gitlab.com/runner/install/

2. 选择Install on Windows

image.png

3. 选择arm64版本,下载到c:\gitrunner-workspace

image.png

4. 将下载的exe重命名为git-runner-x64.exe

二、注册和运行runner

1. 编辑agent.bat,内容如下

@echo ****************************************************************
@echo ******************AUTO START AGENT******************************
@echo ****************************************************************

::echo off
@if "%1" neq "debug" (
    ::is not debug mod, echo off
    echo off
)

::read config
@for /f "tokens=1,2 delims==" %%i in (config.ini) do (
if "%%i"=="server" set server=%%j
if "%%i"=="token" set token=%%j
if "%%i"=="agent_executor" set agent_executor=%%j
if "%%i"=="agent_workspace" set agent_workspace=%%j
if "%%i"=="agent_cachespace" set agent_cachespace=%%j
if "%%i"=="agent_name" set agent_name=%%j
if "%%i"=="agent_desc" set agent_desc=%%j
if "%%i"=="agent_labels" set agent_labels=%%j
)

::check config
if "%server%" EQU "" (
    echo [ERROR]:server can't be null 
    goto err_stop
)
if "%token%" EQU "" (
    echo [ERROR]:token can't be null 
    goto err_stop
)
if "%agent_executor%" EQU "" (
    echo [WARNNING]:agent_executor is not setted, set it to shell
    set agent_executors=shell
)
if "%agent_workspace%" EQU "" (
    echo [WARNNING]:agent_workspace is null, set it to %cd%
    set agent_workspace=%cd%
)
if "%agent_name%" EQU "" (
    echo [ERROR]:agent_name can't be null 
    goto err_stop
)
if "%agent_desc%" EQU "" (
    echo [ERROR]:agent_desc can't be null 
    goto err_stop
)
if "%agent_labels%" EQU "" (
    echo [ERROR]:agent_labels can't be null 
    goto err_stop
)
echo server:%server%
echo token:%token%
echo agent_executor:%agent_executor%
echo agent_workspace:%agent_workspace%
echo agent_workspace:%agent_cachespace%
echo agent_name:%agent_name%
echo agent_desc:%agent_desc%
echo agent_labels:%agent_labels%

::start agent
set CI_SERVER_URL=%server%
set REGISTRATION_TOKEN=%token%
set RUNNER_EXECUTOR=%agent_executor%
set RUNNER_BUILDS_DIR=%agent_workspace%
REM set RUNNER_CACHE_DIR="%agent_cachespace%"
set RUNNER_NAME=%agent_name%
set RUNNER_DESC=%agent_desc%
set RUNNER_TAG_LIST=%agent_labels%
set REGISTER_NON_INTERACTIVE=true
set REGISTER_LOCKED=true
set REGISTER_RUN_UNTAGGED=false

if "%PROCESSOR_ARCHITECTURE%"=="x86" (set agent=git-runner-x86.exe)
if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (set agent=git-runner-x64.exe)

%agent% register

@if "%errorlevel%" EQU "0" (
    %agent% install
)

@if "%errorlevel%" EQU "0" (
    %agent% start
)

::error handler
:err_stop
pause

编辑配置文件
修改config.ini文件中的下面字段:
A) server
按照下面两个图中步骤获取serer地址,填入ini配置中
B) token
按照下面两个图中步骤获取token,填入ini配置中
C) agent_workspace
打包机工作路径,自定填写
D) 其他字段根据需要填写


image.png image.png
  1. 以管理员身份运行CMD
  2. 运行脚本
    ./agent.bat

看见下图所示信息表示成功注册


image.png

注意: 注册agent成功后,agent会以“系统服务”的形式在后台运行,并随开机启动
因此不需要重复注册,也不需要手动启动。

相关文章

  • Gitlab-Runner-Shell

    Runner支持运行在windows/mac/linux环境下 这里以在windows环境下安装runner为例 ...

网友评论

    本文标题:Gitlab-Runner-Shell

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