我尝试使用我的反应应用程序设置gitlab页面,但它显示404错误

时间:2018-03-29 22:45:39

标签: javascript gitlab gitlab-ci gitlab-pages

我尝试使用我的反应应用程序设置gitlab页面,但是,我无法这样做,因为它没有为我生成任何网址。我已经设置了gitlab-ci.yml。

> image: node:latest
pages:
  script:
    - npm install
    - npm run build
    - mkdir public2
    - mv public/* public2
  artifacts:
    paths:
      - public2
  only:
    - master
  stage: deploy

2 个答案:

答案 0 :(得分:0)

我很确定

string base64_encoded_data = "UEsDBBQAAAAIAI1Wp0xrN4dXHwIAA...." //Size = 1,801,048
string base64_decoded_data = base64_decode(base64_encoded_data);

需要

artifacts:
    paths:
      - public2

因此您也可以删除artifacts: paths: - public 命令 构建将成功但部署将失败,除非路径是公共的。

答案 1 :(得分:0)

为React应用设置Gitlab页面的示例:

步骤1:我创建了一个React项目并将其推送到gitlab

$ create-react-app hello-react

这是仓库:https://gitlab.com/ygou/hello-react

步骤2:创建了.gitlab-ci.yml,如下所示

https://gitlab.com/ygou/hello-react/blob/master/.gitlab-ci.yml

# Using the node alpine image to build the React app
image: node:alpine

# Announce the URL as per CRA docs
# https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#advanced-configuration
variables:
  PUBLIC_URL: /hello-react

# Cache node modules - speeds up future builds
cache:
  paths:
  - node_modules

# Name the stages involved in the pipeline
stages:
- deploy

# Job name for gitlab to recognise this results in assets for Gitlab Pages
# https://docs.gitlab.com/ee/user/project/pages/introduction.html#gitlab-pages-requirements
pages:
  stage: deploy
  script:
    - npm install # Install all dependencies
    - npm run build --prod # Build for prod
    - cp public/index.html public/404.html # Not necessary, but helps with https://medium.com/@pshrmn/demystifying-single-page-applications-3068d0555d46
    - mv public _public # CRA and gitlab pages both use the public folder. Only do this in a build pipeline.
    - mv build public # Move build files to public dir for Gitlab Pages
  artifacts:
    paths:
    - public # The built files for Gitlab Pages to serve
  only:
    - master # Only run on master branch

工作完成

CI / CD作业完成后,您可以看到React应用程序的Gitlab页面:

https://ygou.gitlab.io/hello-react/

参考https://ohmybuck.com/posts/2018-08-12-build-a-react-website-with-full-cicd-in-two-minutes/