You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

分支流水线定义与执行优先级问题求助

分支流水线定义与执行优先级问题求助

看起来你遇到了分支流水线规则匹配优先级的核心问题——当同一个分支能匹配多条流水线规则时,系统只会执行从上到下找到的第一条匹配规则,后面的规则会直接被忽略,这就是你单独定义的dev和rev分支步骤完全没执行的原因,哪怕加了if条件也没用,因为那些规则根本没被触发。

先帮你拆解下当前配置的问题:你先写了'{dev,rev}'这个分组分支规则,它会同时匹配dev和rev分支,一旦匹配成功,就会执行下面的build-test和Lint步骤,而后面单独写的dev:和rev:规则因为排在分组规则之后,永远不会被触发。

下面给你两种实用的解决思路,你可以根据自己的需求选择:

方法1:调整规则顺序,拆分分支专属流水线

如果dev和rev分支的执行步骤差异较大,建议把具体分支的规则放在分组规则前面,确保先匹配到专属规则,同时把该分支需要的所有步骤都整合进去:

definitions:
  steps:
    - step: &build-test
        name: 'Build and test'
        script:
          - echo "Your build and test goes here..."
    - step: &Lint
        name: 'Lint'
        script:
          - echo "Your linting goes here..."
    - step: &Securityscan
        name: 'Security scan'
        script:
          - echo "Your security scan goes here..."
    - step: &Deploy-step
        name: 'Deploy-step'
        deployment: staging
        script:
          - echo "your deployment"

pipelines:
  branches:
    dev:                          # 先匹配dev分支,执行全量步骤
      - step: *build-test
      - step: *Lint
      - step: *Securityscan
    rev:                          # 再匹配rev分支,执行专属步骤
      - step: *build-test
      - step: *Lint
      - step: *Deploy-step
      name: "Deploying to prod"
    # 若有其他需要执行基础步骤的分支,可保留此分组规则
    # '{feature/*,hotfix/*}':
    #   - step: *build-test
    #   - step: *Lint

方法2:用条件判断复用基础步骤

如果dev和rev的基础步骤完全一致,只是额外步骤不同,推荐在分组规则里给专属步骤添加分支条件判断,避免重复代码:

definitions:
  steps:
    - step: &build-test
        name: 'Build and test'
        script:
          - echo "Your build and test goes here..."
    - step: &Lint
        name: 'Lint'
        script:
          - echo "Your linting goes here..."
    - step: &Securityscan
        name: 'Security scan'
        script:
          - echo "Your security scan goes here..."
        condition: $BITBUCKET_BRANCH = 'dev'
    - step: &Deploy-step
        name: 'Deploy-step'
        deployment: staging
        script:
          - echo "your deployment"
        condition: $BITBUCKET_BRANCH = 'rev'

pipelines:
  branches:
    '{dev,rev}':
      - step: *build-test
      - step: *Lint
      - step: *Securityscan
      - step: *Deploy-step
    rev:
      name: "Deploying to prod"

这样dev分支会自动跳过Deploy-step,rev分支会自动跳过Securityscan,完美实现分支差异化执行。

备注:内容来源于stack exchange,提问作者vigneshse88

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.22 14:09:36