可以使用BitBucket管道中的variables和conditional语句来避免在两个分支中重复代码部署。例如,以下代码段使用'$BRANCH”变量和条件语句来仅在master分支上执行特定命令:
script:
  - |
    if [[ "$BRANCH" == "master" ]]; then
      # run commands specific to master branch
      command1
      command2
    else
      # run other commands, or nothing
      command3
    fi
这样可以在不创建多个重复性管道的情况下在不同分支上执行不同的部署/构建操作。