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

Bitbucket Pipeline部署React项目时LOCAL_PATH配置报错求助

解决Bitbucket Pipeline部署React项目的LOCAL_PATH配置问题

问题分析

你的Build步骤已正确生成React构建产物,并通过artifacts: - ./frontend/build/**传递到Deploy步骤,但使用atlassian/scp-deploy管道时,LOCAL_PATH的路径写法不符合管道要求,导致各类错误:

  • ./frontend/build/*:仅匹配build目录下的直接文件/子目录,无法覆盖所有嵌套内容,不符合管道的glob匹配规则
  • ./build/*:Deploy步骤中不存在该路径——artifacts会保留原路径结构,构建产物仍存放在./frontend/build/目录下
  • ./:管道不支持直接上传当前目录的.符号,必须指定具体的文件或目录匹配规则

正确配置方案

修改Deploy步骤的LOCAL_PATH为./frontend/build/**,该写法会匹配build目录下的所有文件及子目录,完全符合scp-deploy管道的路径要求:

- step:
    name: Deploy to Staging
    deployment: Staging
    script:
      - pipe: atlassian/scp-deploy:0.3.3
        variables:
          USER: $USER
          SERVER: $SERVER
          REMOTE_PATH: '/var/www/html'
          LOCAL_PATH: './frontend/build/**'

额外优化建议

  1. 移除重复的npm audit fix --force命令,执行一次即可:
    script:
      - npm install --prefix ./frontend/ --legacy-peer-deps
      - npm audit fix --force --prefix ./frontend/
      - npm run build --prefix ./frontend/
    
  2. 在Build步骤中添加构建结果校验,确保build目录生成成功后再传递artifacts:
    script:
      - npm install --prefix ./frontend/ --legacy-peer-deps
      - npm audit fix --force --prefix ./frontend/
      - npm run build --prefix ./frontend/
      - test -d ./frontend/build && echo "Build目录生成成功" || (echo "构建失败:未生成build目录" && exit 1)
    artifacts:
      - ./frontend/build/**
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 03:01:22