zoukankan      html  css  js  c++  java
  • gitlab-runner安装配置

    安装gitlab-runner

    # For RHEL/CentOS/Fedora

    curl -L https://packages.gitlab.com/install/repositories/runner/gitlabrunner/script.rpm.sh | sudo bash

    # For RHEL/CentOS/Fedora

    yum install gitlab-ci-multi-runner

    gitlab-runner注册

    首先要先获取gitlab-ci的Token:

    执行gitlab-runner register注册,输出URL,Token,描述,tag,执行器等

    编写.gitlab-ci.yml触发器

    stages:
        - 构建打包
        - 生成镜像
    
    variables:
        VERSION: 'latest'
        SVCNAME: 'portal'    
    
    cache:
        paths:
            - node_modules #设置cache,不用每次构建去下载依赖
    
    build: 
        stage: 构建打包
        tags:
            - test #设置使用gitlab-runner服务器的tag,如果有多个gitlab-runner
        only:
            - release/test
        script:
            npm run release-build
        artifacts:
            paths:
                - tar #将tar目录传递给下一个job,防止被删除
    
    docker:
        stage: 生成镜像
        tags:
            - test
        only:
            - release/test
        variables:
            GIT_STRATEGY: none #配合cache、artifacts使用。设置为none的job里应该依赖从cache或者artifacts来的数据,而不是从仓库获取数据。
        before_script: #使用命令生成Dockerfile,也可以将Dockerfile单独存放
            - echo FROM node >Dockerfile
            - echo RUN mkdir -p /opt/portal >>Dockerfile
            - echo ADD ./tar/*.tar.gz /opt/portal >>Dockerfile
            - echo WORKDIR /opt/portal >>Dockerfile
            - echo CMD node server/server.js >>Dockerfile
        script:
            - echo "docker build -t ${SVCNAME}:${VERSION} ."
            - docker build -t ${SVCNAME}:${VERSION} .

    [[.gitlab-ci.yml]] 相关参数

    https://docs.gitlab.com/ee/ci/yaml/

    KeywordDescription
    script Shell script which is executed by Runner.
    image Use docker images. Also available: image:name and image:entrypoint.
    services Use docker services images. Also available: services:nameservices:aliasservices:entrypoint, and services:command.
    before_script Override a set of commands that are executed before job.
    after_script Override a set of commands that are executed after job.
    stage Defines a job stage (default: test).
    only Limit when jobs are created. Also available: only:refsonly:kubernetesonly:variables, and only:changes.
    except Limit when jobs are not created. Also available: except:refsexcept:kubernetesexcept:variables, and except:changes.
    rules List of conditions to evaluate and determine selected attributes of a job, and whether or not it’s created. May not be used alongside only/except.
    tags List of tags which are used to select Runner.
    allow_failure Allow job to fail. Failed job does not contribute to commit status.
    when When to run job. Also available: when:manual and when:delayed.
    environment Name of an environment to which the job deploys. Also available: environment:nameenvironment:urlenvironment:on_stopenvironment:auto_stop_in and environment:action.
    cache List of files that should be cached between subsequent runs. Also available: cache:pathscache:keycache:untracked, and cache:policy.
    artifacts List of files and directories to attach to a job on success. Also available: artifacts:pathsartifacts:expose_asartifacts:nameartifacts:untrackedartifacts:whenartifacts:expire_inartifacts:reportsartifacts:reports:junitartifacts:reports:cobertura, and artifacts:reports:terraform.

    In GitLab Enterprise Edition, these are available: artifacts:reports:codequalityartifacts:reports:sastartifacts:reports:dependency_scanningartifacts:reports:container_scanningartifacts:reports:dastartifacts:reports:license_managementartifacts:reports:performance and artifacts:reports:metrics.
    dependencies Restrict which artifacts are passed to a specific job by providing a list of jobs to fetch artifacts from.
    coverage Code coverage settings for a given job.
    retry When and how many times a job can be auto-retried in case of a failure.
    timeout Define a custom job-level timeout that takes precedence over the project-wide setting.
    parallel How many instances of a job should be run in parallel.
    trigger Defines a downstream pipeline trigger.
    include Allows this job to include external YAML files. Also available: include:localinclude:fileinclude:template, and include:remote.
    extends Configuration entries that this job is going to inherit from.
    pages Upload the result of a job to use with GitLab Pages.
    variables Define job variables on a job level.
    interruptible Defines if a job can be canceled when made redundant by a newer run.
    resource_group Limit job concurrency.

    [[runners]] 相关参数

    https://docs.gitlab.com/runner/configuration/advanced-configuration.html

    /etc/gitlab-runner/config.toml

    SettingDescription
    name The Runner’s description, just informatory
    url GitLab URL
    token The Runner’s special token (not to be confused with the registration token)
    tls-ca-file File containing the certificates to verify the peer when using HTTPS
    tls-cert-file File containing the certificate to authenticate with the peer when using HTTPS
    tls-key-file File containing the private key to authenticate with the peer when using HTTPS
    limit Limit how many jobs can be handled concurrently by this token. 0 (default) simply means don’t limit
    executor Select how a project should be built, see next section
    shell Name of shell to generate the script. Default value is platform dependent.
    builds_dir Absolute path to a directory where builds will be stored in context of selected executor (Locally, Docker, SSH)
    cache_dir Absolute path to a directory where build caches will be stored in context of selected executor (locally, Docker, SSH). If the docker executor is used, this directory needs to be included in its volumes parameter.
    environment Append or overwrite environment variables
    request_concurrency Limit number of concurrent requests for new jobs from GitLab (default 1)
    output_limit Set maximum build log size in kilobytes, by default set to 4096 (4MB)
    pre_clone_script Commands to be executed on the Runner before cloning the Git repository. this can be used to adjust the Git client configuration first, for example. To insert multiple commands, use a (triple-quoted) multi-line string or “ ” character.
    pre_build_script Commands to be executed on the Runner after cloning the Git repository, but before executing the build. To insert multiple commands, use a (triple-quoted) multi-line string or “ ” character.
    post_build_script Commands to be executed on the Runner just after executing the build, but before executing after_script. To insert multiple commands, use a (triple-quoted) multi-line string or “ ” character.
    clone_url Overwrite the URL for the GitLab instance. Used if the Runner can’t connect to GitLab on the URL GitLab exposes itself.
    debug_trace_disabled Disables the CI_DEBUG_TRACE feature. When set to true, then debug log (trace) will remain disabled even if CI_DEBUG_TRACE will be set to true by the user.
    referees Extra job monitoring workers that pass their results as job artifacts to GitLab

    参考:

    https://www.jianshu.com/p/fab407ddfed0

    https://segmentfault.com/a/1190000011890710

  • 相关阅读:
    二叉树【基础算法题】
    大话数据结构笔记——第五章 串
    大话数据结构笔记——第四章 栈与队列
    矩阵【基础算法题】
    大话数据结构笔记——第三章 线性表
    十大经典排序算法(Javascript版)
    比较器
    荷兰国旗问题
    好听的字
    mongodb 命令
  • 原文地址:https://www.cnblogs.com/wsl222000/p/12876464.html
Copyright © 2011-2022 走看看