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

Bitbucket Pipelines报Staging部署环境重复配置错误如何解决

问题原因

Bitbucket Pipelines有明确规则限制:同一个流水线执行流程中,同一个部署环境名称不能被多个步骤声明使用。你当前的dev分支流水线中同时调用了两个声明deployment: Staging的步骤,因此触发了报错。
此外你原有配置还存在YAML锚点合并语法错误:master分支下直接在*build步骤后追加<<: *deploychanges的写法不符合规范,会导致配置解析失败。

修复方案

有两种常用方案可以解决该问题:

  • 方案一(最推荐):合并同环境的部署步骤:将两个Staging环境的部署逻辑合并到同一个步骤中,既避免重复声明同环境,还能减少重复的依赖安装操作,提升流水线执行效率。
  • 方案二:拆分环境命名:如果确实需要分开执行两个部署步骤,可以给同环境的不同步骤添加专属后缀,比如Staging-changes、Staging-compiled,对应名称在Bitbucket后台单独配置环境变量即可。

以下是基于方案二调整后的完整可用配置,同时修正了原有的语法错误:

image: ubuntu:18.04

definitions:
    steps:
        - step: &build
            name: npm-build
            condition:
                changesets:
                    includePaths:
                        # 只有build目录变更时才执行构建步骤
                        - "build/**"
            image: node:14.17.5
            script:
              - echo 'build initiated'
              - cd build
              - npm install
              - npm run dev
              - echo 'build complete'
            artifacts:
              - themes/factor/css/**
              - themes/factor/js/**
        # 移除模板中的默认deployment声明,后续调用时再传值避免重复
        - step: &deploychanges
            name: Deploy_Changes
            script:
              - echo 'Installing server dependencies'
              - apt-get update -q
              - apt-get install -qy software-properties-common
              - add-apt-repository -y ppa:git-ftp/ppa
              - apt-get update -q
              - apt-get install -qy git-ftp
              - echo 'All dependencies installed'
              - echo 'Transferring changes'
              - git ftp init --user $FTP_USER --passwd $FTP_PASSWORD $FTP_ADDRESS push --force --changed-only -vv
              - echo 'File transfer complete'
        
        - step: &deploycompiled
            name: Deploy_Compiled
            condition:
                changesets:
                    includePaths:
                        # 只有build目录变更时才执行编译资源部署
                        - "build/**"
            script:
              - echo 'Installing server dependencies'
              - apt-get update -q
              - apt-get install -qy software-properties-common
              - add-apt-repository -y ppa:git-ftp/ppa
              - apt-get update -q
              - apt-get install -qy git-ftp
              - echo 'All dependencies installed'
              - echo 'Transferring compiled assets'
              - git ftp init --user $FTP_USER --passwd $FTP_PASSWORD $FTP_ADDRESS push --all --syncroot themes/factor/css/ -vv
              - git ftp init --user $FTP_USER --passwd $FTP_PASSWORD $FTP_ADDRESS push --all --syncroot themes/factor/js/ -vv
              - echo 'File transfer complete'

pipelines:
    branches:
        master:
            - step: *build
            - step:            
                <<: *deploychanges
                deployment: Production
            - step:            
                <<: *deploycompiled
                deployment: Production-compiled

        dev:
            - step: *build
            - step: 
                <<: *deploychanges
                deployment: Staging
            - step: 
                <<: *deploycompiled
                deployment: Staging-compiled

内容的提问来源于stack exchange,提问作者hdwebpros

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.06 06:48:01