代码之家  ›  专栏  ›  技术社区  ›  Bartłomiej Semańczyk

如何只为特定的分支和标记运行Gitlab CI?

  •  1
  • Bartłomiej Semańczyk  · 技术社区  · 7 年前

    我想设置我的 project_dev CI仅适用于3个分支和特定类型的标记,如: .

    我怎样才能做到这一点?

    这就是我现在所拥有的:

    project_dev:
      stage: dev
      script:
        - export
        - bundle exec pod repo update
        - bundle exec pod install
        - bundle exec fastlane crashlytics_project_dev
      after_script:
        - rm -rf ~/Library/Developer/Xcode/Archives || true
      when: manual
      only:
        - develop
        - release
        - master
        - //here I need to add condition to fire that stage additionally only for specific tags. How can I setup regexp here?
      tags:
        - iOS
    

      only:
        - branches
        - /^dev_[0-9.]*$/
    

    它还为以下标记运行CI: 版本1.2 但不应该。为什么?有标签的regexp吗?

    2 回复  |  直到 7 年前
        1
  •  34
  •   Gasol    7 年前

    听起来像个正则表达式问题。我刚创建了一个 project 在gitlab.com上 the regular expression

    文件: .gitlab-ci.yml

    project_dev:
      # Irrelevant keys is skipped
      script:
        - echo "Hello World"
      only:
        - develop
        - release
        - master
        - /^dev_[0-9]+(?:.[0-9]+)+$/ # regular expression
    

    我被推了 all of tags 你提到要测试这个正则表达式。

    Tags

    dev_1.0 , dev_1.1 ,但是工作 project_dev 不会由标记触发 dev1.2 ,您可以在上查看结果 pipeline 页

    Pipelines

        2
  •  7
  •   Hiruma    7 年前

    你可以试试 except 和 only . 像这样的

    only: 
    - tags 
    - branches 
    except:
    - /^(?!(branch1|branch2|branch3|dev_[0-9.]*$)$).*$/
    

    其思想是,只允许分支和标记触发作业,除了分支[1-3]和开发分支/标记之外的所有内容

        3
  •  6
  •   Jakob Liskow    5 年前

    而不是使用 仅/除外 你可以用 rules 它们的威力更大。

    规则支持 regex pattern matching .

    你的规则只排除特定种类的分支/标签,比如 开发1.0 , , 开发1.2

    rules:
        - if: '$CI_COMMIT_BRANCH =~ /^dev_[0-9]+\.[0-9]+$/ || $CI_COMMIT_TAG =~ /^dev_[0-9]+\.[0-9]+$/'
    

    预定义的环境变量,如 和 CI\提交\标记 描述 here

        4
  •  0
  •   Marty    5 年前