【问题标题】:How to make a conditional manual approval in CircleCI 2.0 workflows如何在 CircleCI 2.0 工作流程中进行有条件的手动批准
【发布时间】:2018-04-14 22:37:39
【问题描述】:

我有一个简单的用例,我只想为特定的分支和/或标签创建manual approval

type:approval 的工作流作业与所有其他作业一样具有过滤器,但需要手动批准(或不需要)的作业 foo 将使用 requires: ['approve'] 之类的内容,然后与其强链接.

这意味着如果批准步骤与过滤器不匹配,foo 将永远不会发生。

所以.. 任何干净的解决方法,在 yaml 文件中没有很多重复项?

编辑:Same question on CircleCI Discuss

【问题讨论】:

    标签: continuous-integration yaml circleci circleci-workflows


    【解决方案1】:

    使用YAML alias map

    这是一种 hack,但使用 YAML alias map,您可以重复使用您的步骤,并使用不同的过滤器创建两条独​​立的工作流路径:一个有批准,另一个没有批准。

    这是一个完整的例子:

    version: 2.0
    
    # Run job (defined in a YAML alias map, see http://yaml.org/type/merge.html)
    run-core: &run-core
        docker:
          - image: circleci/node:8
        steps:
          - checkout
          - restore_cache: { key: 'xxxxx' }
          - run: npm install
          - save_cache: { key: 'xxxxx', paths: ['xxxx'] }
          - run: npm run build
          - run: npm run validate
          - deploy: ./scripts/deploy.sh
    
    # Jobs (duplicate the same job, but with different names)
    jobs:
      run:
        <<: *run-core
      run-with-approval:
        <<: *run-core
    
    # This will allow manual approval and context
    # See https://circleci.com/docs/2.0/workflows/#git-tag-job-execution
    workflows:
      version: 2
      run:
        jobs:
          # Without approval (for all branches except staging)
          - run:
              context: org-global
              filters:
                branches: { ignore: 'staging' } # All branches except staging
                tags: { ignore: '/.*/' }        # Ignore all tags
          # With approval (only for tags and staging branch)
          - run-with-approval:
              context: org-global
              filters:
                tags: { only: '/.*/' }          # All branches and all tags
              requires: ['approve']             # But requires approval (which is filtering)
          - approve:
              type: approval
              filters:
                branches: { only: 'staging' }   # Ignore all branches except staging
                tags: { only: '/.*/' }          # All tags
    

    希望对你有帮助

    【讨论】:

      【解决方案2】:

      用更新的答案更新这个问题: CircleCI 有一个预览版的 v2 API(以支持 CircleCI 2.1),它支持条件工作流(即条件保持步骤)

      conditional workflow formatting

      - when:
          condition: << pipeline.parameters.test >>
          steps:
            - hold-step
      

      【讨论】:

        猜你喜欢
        • 2021-02-25
        • 2021-06-15
        • 2018-11-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-10-16
        相关资源
        最近更新 更多