从Gitlab到Firebase的React部署失败,并出现以下错误:到指定的公共目录“ build”不存在,无法将主机部署到站点

时间:2020-10-05 16:01:51

标签: reactjs firebase gitlab-ci firebase-hosting

这是firebase.json文件

{
  "hosting": {
    "public": "build",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

这是我的.gitlab-ci.yml

image: tragopoulos/firebase:latest

stages:
  - build
  - test
  - deploy

cache:
  paths:
    - node_modules/
  key: "$CI_BUILD_REPO"

build:
  stage: build
  image: node
  script:
    - echo "# Start building App"
    - npm install
    - npm build
    - echo "# Build successfully!"
  artifacts:
    expire_in: 1 hour
    paths:
      - "/build"
      - node_modules/

test:
  stage: test
  image: node
  script:
    - echo "# Testing App"
    - npm install
    - CI=true npm test
    - echo "# Test successfully!"

deploy-develop:
  stage: deploy
  environment: tragopoulos-portfolio-dev
  only:
    - develop
  before_script:
    - npm install
    - npm build
  script:
    - echo "# Deploying App"
    - firebase use tragopoulos-portfolio --token $FIREBASE_TOKEN
    - firebase deploy --only hosting -m "Pipeline $CI_PIPELINE_ID Build $CI_BUILD_ID"
    - echo "# Deployed successfully!"

这是错误:

enter image description here

我尝试了“ build”,“ / build”,“ / build /”,“ / PROJECT_NAME / build”,但没有任何效果。我也不知道如何$ echo构建路径,因此我可以在项目中对其进行调试。在Angular中,“ dist”可以正常工作。有想法吗?

1 个答案:

答案 0 :(得分:1)

根据评论部分的讨论,似乎在部署步骤中没有创建build文件夹。它们很可能在不同的容器中运行。因此,firebase deploy命令找不到必要的build

我会尝试从before_script中删除.gitlab-ci.yml,并将其步骤与script合并为:

  script:
    - npm install
    - npm build
    - echo "# Deploying App"
    - firebase use tragopoulos-portfolio --token $FIREBASE_TOKEN
    - firebase deploy --only hosting -m "Pipeline $CI_PIPELINE_ID Build $CI_BUILD_ID"
    - echo "# Deployed successfully!"

这样,您就可以在部署步骤中放置build文件夹了。