Bitbucket 管道将触发器限制为分支

Bitbucket Pipelines limit trigger to branches

我想限制特定步骤到特定分支

pipelines:
  branches:
    '{feature/*,release/*,hotfix/*,bugfix/*}':
      - step: # Generates credential needed for test and building
          script:
            - echo "All branch, this step is needed for release"
      - parallel:
          script: # Some lint and unit test script
            - echo "All branch, this step is needed for release step"
    '{release/*}':
      - step: # Actual test and build script
          script:
            - echo "Only in release branch"

在上面的示例中,我希望在几乎所有分支中第一步到 运行,但第二步应该只对 release 分支模式执行。不幸的是,实际结果是第一步仅在 hotfix 等分支中有效,并且在分支时永远不会在 release/version-name 中触发。它是如何完成的?基本上这个想法是在 release 分支上重用上面的前两个步骤,所以不需要重复这些步骤。

我终于用 YAML 锚点做到了

definitions:
  steps:
      - step: &key-generator # Generates credential needed for test and building
          name: Generating Key
          script:
            - echo "All branch, this step is needed for release"
      - parallel: &lint-test
          name: Lint check
          script: # Some lint and unit test script
            - echo "All branch, this step is needed for release step"
pipelines:
  branches:
    '{feature/*,release/*,hotfix/*,bugfix/*}':
      - step: *key-generator # YAML anchor referer
      - parallel: *lint-test # YAML anchor referer
    '{release/*}':
      - step: *key-generator # YAML anchor referer
      - parallel: *lint-test # YAML anchor referer
      - step: # Actual test and build script
          script:
            - echo "Only in release branch"