RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 1218236
Accepted
hedgehogues
hedgehogues
Asked:2021-12-14 00:43:32 +0000 UTC2021-12-14 00:43:32 +0000 UTC 2021-12-14 00:43:32 +0000 UTC

gitlab中的继承

  • 772

我想学习如何继承.gitlab. 我在文档中找到了如何做到这一点。这可以通过before_script和来完成after_script。描述在这里。通过继承,我的意思是重用代码的能力:

default:
  before_script:
    - IMAGE=${IMAGE} make build
    - IMAGE=${VERSION} make run

golang-tesseract:
  when: manual
  variables:
    VERSION: test
    IMAGE: golang-tesseract
  script:
    - echo "Finished"

因此,在这种情况下,在启动时,它将golang-tesseract首先执行before_scriptfromdefault然后 -- script。在这种情况下,变量将从golang-tesseract. 但script我还有一个不必要的命令。有可能摆脱它吗?该文档.gitlab明确指出每条规则都有一个必需的部分script。也许有一些解决方法?

gitlab
  • 2 2 个回答
  • 10 Views

2 个回答

  • Voted
  1. Best Answer
    gore
    2021-12-26T22:58:37Z2021-12-26T22:58:37Z

    gitlab 中的继承 这可以通过 before_script 和 after_script 来完成。

    before_scriptafter_script这根本不是关于继承的,而是关于脚本之前和之后的。

    你需要.job_template,它们是锚(anchors),更多细节在这里: https ://docs.gitlab.com/ee/ci/yaml/#anchors

    解决方案,以及使用继承的示例:

    1. 通过anchor和extends:

      .pytest_template:  # это anchor, джоба с точкой в начале является якорем, от которого можно наследоваться
      script:
        - pytest $TESTS
      
      test_first:
        extends: .pytest_template  # это само наследование через extends свойство джобы
        variables:
          TESTS: '/first'  # в итоге выполнится скрипт "pytest /first"
      
      test_second:
        extends: .pytest_template
        variables:
          TESTS: '/second'  # в итоге выполнится скрипт "pytest /second"
      
    2. 通过别名alias:

      .job_template: &job_definition  # Hidden key that defines an anchor named 'job_definition'
        image: ruby:2.6
        services:
          - postgres
          - redis
      
      test1:
        <<: *job_definition           # Merge the contents of the 'job_definition' alias
        script:
          - test1 project
      
      test2:
        <<: *job_definition           # Merge the contents of the 'job_definition' alias
        script:
          - test2 project
      
    3. 既然我们在谈论脚本,甚至脚本也可以被继承:

      .some-script: &some-script
        - echo "Execute this script in `before_script` sections"
      
      .some-script-before: &some-script-before
        - echo "Execute this script in `script` sections"
      
      .some-script-after: &some-script-after
        - echo "Execute this script in `after_script` sections"
      
      job_name:
        before_script:
          - *some-script-before
        script:
          - *some-script
        after_script:
          - *some-script-after
      
    • 1
  2. Alexander Pavlov
    2021-12-16T01:32:58Z2021-12-16T01:32:58Z

    !!两个选项都不行!!

    1. 您可以在基本任务script而不是before_script. 那么后继者中不需要该脚本

    2. 您可以尝试在继任者中执行此操作script: [](不确定是否可行)

    可以代替default使用extends

    .default:
      script:
        - IMAGE=${IMAGE} make build
        - IMAGE=${VERSION} make run
    
    golang-tesseract:
      extends: .default
      when: manual
      variables:
        VERSION: test
        IMAGE: golang-tesseract
    
    • 0

相关问题

  • 如何让 GitLab Pages 主机在正确的文件夹中显示?

  • .gitlab-ci.yml 文件的以下代码片段有什么作用?

  • 在 Gitlab CI/CD 中按时运行作业

  • GitLab 的商业用途

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    如何从列表中打印最大元素(str 类型)的长度?

    • 2 个回答
  • Marko Smith

    如何在 PyQT5 中清除 QFrame 的内容

    • 1 个回答
  • Marko Smith

    如何将具有特定字符的字符串拆分为两个不同的列表?

    • 2 个回答
  • Marko Smith

    导航栏活动元素

    • 1 个回答
  • Marko Smith

    是否可以将文本放入数组中?[关闭]

    • 1 个回答
  • Marko Smith

    如何一次用多个分隔符拆分字符串?

    • 1 个回答
  • Marko Smith

    如何通过 ClassPath 创建 InputStream?

    • 2 个回答
  • Marko Smith

    在一个查询中连接多个表

    • 1 个回答
  • Marko Smith

    对列表列表中的所有值求和

    • 3 个回答
  • Marko Smith

    如何对齐 string.Format 中的列?

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5