【问题标题】:In Gitlab CI, cancel pipeline on master when I push a tag在 Gitlab CI 中,当我推送标签时取消 master 上的管道
【发布时间】:2020-09-12 23:33:21
【问题描述】:

我有这个 .gitlab-ci.yml 文件:

    image: node:latest
    
    stages:
      - build
      - test
      - publish
    
    cache:
      key:
        files:
          - package.json
          - package-lock.json
      paths:
        - node_modules
    
    build:
      stage: build
      script:
        - echo -e "//my.private.repo.com/:_authToken=${NPM_TOKEN}\n$(cat .npmrc)">.npmrc
        - npm install
        - npm run build
      artifacts:
        paths:
          - node_modules
          - .npmrc
    
    test:
      stage: test
      script:
        - npm test
    
    publish:
      stage: publish
      script:
        - npm publish
      only:
        - tags

使用此配置,当我推送一个简单的提交时,一切正常:按预期构建 + 测试。

但是,当我推送标签(在此处使用npm version 创建时,会创建两个管道:1 个用于提交,1 个用于标签。因此,构建和测试执行了两次。

我可以做些什么来防止这种行为,并让标签管道“取消”提交管道

【问题讨论】:

    标签: gitlab-ci


    【解决方案1】:

    当你推送一个简单的提交或标签时,你可以有不同的工作,并使用 onlyexcept 关键字来区分情况,否则这是 GitLab 考虑的正确行为。您可以查看围绕已关闭问题 here 的讨论。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-12
      • 1970-01-01
      • 2019-01-13
      • 2021-12-26
      • 2021-09-06
      • 1970-01-01
      • 2021-02-11
      相关资源
      最近更新 更多