【问题标题】:Gitlab CI - Start Shared Runner for normal reposGitlab CI - 为正常 repos 启动 Shared Runner
【发布时间】:2019-04-12 05:50:50
【问题描述】:

我是 Gitlab CI 的新手。

我已经配置了 .gitlab-ci.yml 文件,并且使用 CI Lint 它已经通过了验证过程。

基于这个documentation,我可以看到应该在虚拟机、VPS、裸机、docker 容器甚至容器集群上配置特定的运行器。

我可以看到 gitlab 有自己的共享运行器,并且 默认启用

当我访问 Pipeline 页面时,我只能看到蓝色的 Get Started with Pipeline 按钮,点击后我被重定向到 this page

Gitlab CI - How to start Shared Runner”表示 Gitlab CI 只会为 testing 分支运行该作业,但是,除非非常特殊的情况,否则我的 git 不会使用分支。所以

问题是如何在我只有一个 master 分支的普通(私人)仓库中使用这个共享运行器?

【问题讨论】:

    标签: git gitlab gitlab-ci gitlab-ci-runner


    【解决方案1】:

    Shared runners 将为 any 分支运行,所以对于 master 分支也是如此(除非您另外配置)。

    另外,

    • 如果您为您的工作定义了tag,则可以选择特定的跑步者。
    • 您可以过滤作业是否将通过only 和/或except 指令触发。

    例如,以下作业将触发任何推送,尽管有分支:

    buildClient:
      stage: buildComponents
      script:
      - echo "Building the client..."
    

    另一方面,这个作业只会在推送到develop 分支时触发,并且它会被任何带有docker 标签的可用运行器处理:

    buildServer:
      stage: buildComponents
      script:
      - echo "Building the server with Docker..."
      only:
      - develop
      tags:
      - docker
    

    根据蓝色的Get Started with Pipeline按钮:您需要将.gitlab-ci.yml 文件添加到项目的根目录并将其推送到GitLab。该文件定义了构建管道的 stagesjobs。然后,跑步者根据给定的配置选择作业。例如。简单的.gitlab-ci.yml 可以是这样的:

    image: alpine:latest
    
    stages:
      - test
      - build
    
    testApp:
      stage: test
      script: echo "Testing..."
    
    buildApp:
      stage: build
      script: echo "Building..."
    

    有关更多详细信息,请参阅 GitLab 文档中的 Configuration of your jobs with .gitlab-ci.yml

    【讨论】:

    • 感谢 Vit 的回复。既然我知道 Shared runners 将在任何分支上运行,我需要克服的下一个障碍是,为什么当我访问 Pipeline 页面时,我只能看到蓝色的 Get Started with Pipeline 按钮,即使我的共享运行器已启用?一定有一个步骤我错过了。谢谢。
    • @xpt 我在答案的末尾添加了一个额外的解释。推送.gitlab-ci.yml 文件后,此按钮将消失,您将看到您的管道。
    • 感谢维特。请给我一些时间尝试并准备一个小演示,因为我无法公开我的分叉回购,参考 gitlab.com/gitlab-org/gitlab-ce/issues/40088
    猜你喜欢
    • 1970-01-01
    • 2021-12-03
    • 2021-12-24
    • 2021-02-16
    • 2022-01-01
    • 2015-10-07
    • 2016-09-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多