代码之家  ›  专栏  ›  技术社区  ›  Swe Zin Phyoe

在多次运行的gitlab CI中进行标记

  •  0
  • Swe Zin Phyoe  · 技术社区  · 3 年前

    我创建了GitLab作业来创建git标记并推送到存储库,如下所示:

      add tag:
      extends: .install_dependencies
      stage: deploy
      image:
        name: nexus-docker.ship.gov.sg/python:latest
        entrypoint: ["/bin/bash"]
      script:
        - echo "This job deploys something from the $CI_COMMIT_BRANCH branch."
        - git tag -a v"$VERSION" -m version"$VERSION"
        - git push origin v"$VERSION"
      rules:
        - if: $CI_COMMIT_BRANCH == $CI_COMMIT_BRANCH
    

    但每次我从提交分支推送时,管道都会被两次触发:从分支,然后标记。 由于标记已经在第一个管道中创建,所以由标记触发的第二个管道失败。根据规则,我只想为这份工作跑一次。

    pipeline triggered 2 times for same commit

    1 回复  |  直到 3 年前
        1
  •  1
  •   Mr.Zeus    3 年前

    在Gitlab CI yaml中有一个关键字 except: 以告诉CI何时不运行。您要做的是将其添加到任务中,使其只运行一次以进行标记,然后在出现标记时忽略标记。这可能是您的管道脚本的样子:

      add tag:
      extends: .install_dependencies
      stage: deploy
      ...
      except:
        - tags
    
      script:
        - echo "This job deploys something from the $CI_COMMIT_BRANCH branch."
      ...
    
    推荐文章