如何使用 Bitbucket Pipelines 将 React 项目部署到 ftp?

How to deploy react project to ftp using Bitbucket Pipelines?

我正在尝试设置 bitbucket-pipelines.yml 文件来进行构建,然后部署 React 项目。下面是我的代码。

image: node:10.15.1 pipelines: default: # Pipelines that are triggered manually via the Bitbucket GUI - step: name: Build script: - yarn - yarn build - step: name: Deploy script: - apt-get update - apt-get install ncftp - ncftpput -v -u "$FTP_USERNAME" -p "$FTP_PASSWORD" -R $FTP_HOST $FTP_SITE_ROOT_DEV build/* - echo Finished uploading /build files to $FTP_HOST$FTP_SITE_ROOT

我得到的结果是:
+ ncftpput -v -u "$FTP_USERNAME" -p "$FTP_PASSWORD" -R $FTP_HOST $FTP_SITE_ROOT_DEV build/* could not stat build/*: No such file or directory. ncftpput build/*: no valid files were specified.
它说没有构建文件或目录。但 yarn build 实际上是 build 文件夹创建:react-scripts build

来自 Atlassian documentation

Key concepts

A pipeline is made up of a set of steps.

  • Each step in your pipeline runs a separate Docker container. If you want, you can use different types of container for each step, by selecting different images

因此,当您尝试在部署步骤中发送它时,它不存在,因为您在另一个容器中构建了它。

要在步骤之间传递文件,您必须使用 Artifacts

image: node:10.15.1
pipelines:
  default: # Pipelines that are triggered manually via the Bitbucket GUI
      - step:
          name: Build
          script:
          - yarn
          - yarn build
          artifacts: # defining build/ as an artifact
          - build/**
      - step:
          name: Deploy
          script:
            - apt-get update
            - apt-get install ncftp
            - ncftpput -v -u "$FTP_USERNAME" -p "$FTP_PASSWORD" -R $FTP_HOST $FTP_SITE_ROOT_DEV build/*
            - echo Finished uploading /build files to $FTP_HOST$FTP_SITE_ROOT