Gitlab CI :- 如何在 Gitlab 中创建不依赖于任何系统的 Shared Runner?

Gitlab CI :- How to create the Shared Runner in Gitlab which does not depend on the any system?

我研究过 Gitlab Runner 有两种类型,一种是 Custom Runner,另一种是 Shared Runner

我使用了 Gitlab 中的 docker 之类的 Custom Runner 来创建 Android[=39 的 apk =].它工作正常并创建所需的构建。但是通过这种方式我得到一个 问题 是它取决于我的系统意味着当我的系统打开时我的 Custom Runner 工作正常但是当我的系统关闭时 Gitlab 执行操作失败,因为它取决于我的系统运行程序。

我读到了 Shared Runner 不依赖于任何东西并执行操作。我已经阅读了文档,但没有找到正确的实现方法。

请检查我的.gitlab-ci.yml下面的文件

image: jangrewe/gitlab-ci-android

stages:
  - build

before_script:
  - export GRADLE_USER_HOME=$(pwd)/.gradle
  - chmod +x ./gradlew

cache:
  key: ${CI_PROJECT_ID}
  paths:
    - .gradle/

build:
  stage: build
  tags:
    - dev-ci
  script:
    - ./gradlew assembleDevelopment assembleProduction assembleStaging
  artifacts:
    paths:
      - app/build/outputs/

请在 Gitlab

Shared Runner 上帮助我

注册共享 运行ner 的步骤:

Pre-requisite: Gitlab-Runner should have been installed. Follow this document for Installing Runner

  • 登录 Gitlab。转到管理区域 >> 概览 >> 运行用户 >> 手动设置共享运行ner

  • 登录到安装了运行ner的服务器,使用root用户或者你安装运行ner的用户(比如gitlab-runner) .在这里,我们使用 root 用户注册 运行ner。 运行 下面的命令:

    gitlab-runner register

  • 根据您的设置填写以下详细信息:

    • 请输入gitlab-ci协调员URL:https://example.com/gitlab/

      (在gitlab中寻找url手动设置共享运行ner)

    • 请输入此 运行 的 gitlab-ci 令牌:jiRS-3KxGaEdkLo6tToZ

      (在手动设置共享运行ner下的gitlab中寻找令牌)

    • 请输入 gitlab-ci 这个 运行 的描述:my-first-shred-runner

      (为 运行ner 输入任何名称)

    • 请为这个 运行ner 输入 gitlab-ci 标签(逗号分隔):ci-shared,ci-task

      (输入您想要与 运行ner 关联的任何标签)

    • 请输入执行器:docker-ssh、parallels、virtualbox、docker+machine、kubernetes、custom、docker、docker-ssh+machine , shell, ssh: shell

      (输入您需要 运行 用户使用的执行器,根据执行器的选择,您将获得其他选项。请查看 executors 的文档)

现在,您可以看到消息运行ner已经注册。

你可以在Gitlab中验证一下。进入Gitlab,Admin Area >> Overview >> 运行ners >> Set set a shared 运行ner manually 可以看到运行 ner 已注册名称 my-first-shred-runner

在 Gitlab 中为项目启用共享 运行ner 的步骤:

  1. 转到 Gitlab 中的项目。
  2. 然后,在项目页面中,设置 >> CI/CD >> 运行用户 >> 共享 运行用户
  3. 然后,点击Enable shared runners。现在,您可以为 Gitlab CI/CD.
  4. 使用共享的 运行ner
  5. .gitlab-ci.yml 中使用与共享 运行ner 关联的标签,以便作业将 运行 使用共享 运行ner。

更改 .gitlab-ci.yml

中的标签
image: jangrewe/gitlab-ci-android

stages:
  - build

before_script:
  - export GRADLE_USER_HOME=$(pwd)/.gradle
  - chmod +x ./gradlew

cache:
  key: ${CI_PROJECT_ID}
  paths:
    - .gradle/

build:
  stage: build
  tags:
    - ci-shared
  script:
    - ./gradlew assembleDevelopment assembleProduction assembleStaging
  artifacts:
    paths:
      - app/build/outputs/

注册具体步骤 运行ner:

  1. 登录 Gitlab。转到项目,然后 设置 >> CI/CD >> 运行ners >> 手动设置特定的 运行ner
  2. 接下来,按照上面为 Registering Shared 运行ner
  3. 提供的步骤 2 中的相同步骤