为不同分支机构部署GitLab页面 [英] Deploying GitLab pages for different branches

查看:164
本文介绍了为不同分支机构部署GitLab页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用GitLab Pages部署我的React应用程序,并且运行良好.

I am deploying my React app using GitLab Pages, and it works well.

这是我的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: /
# Cache node modules - speeds up future builds
cache:
  paths:
  - client/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:
    - cd client
    - 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

现在,我刚刚基于分支develop

Now, I just created a dev version, based on my branch develop

我想要我的React应用程序有2个版本,并带有2个不同的URL.我该怎么办?

I would like to have 2 versions of my React app with 2 different URLs. How can I do that?

例如,现在我有:

my-react-app.com链接到master分支

我应该怎么吃

dev.my-react-app.com甚至是my-react-app.gitlab.io链接到develop分支?

推荐答案

可以为不同的管道/分支发布多个页面.

It is possible to keep several pages published for different pipelines/branches.

为此,您需要将页面内容(基本上是测试报告,或需要发布的内容)复制到公用文件夹中的特定唯一目录. 例如,目录名称可以是管道的ID(CI_PIPELINE_ID).因此,页面来源的路径类似于 public/$ CI_PIPELINE_ID/.

To do that you need to copy your pages content (basically test report, or whatever needs to be published) to specific unique directory in public folder. For example, the name of the directory can be the id of pipeline (CI_PIPELINE_ID). So the path to pages sources would be like public/$CI_PIPELINE_ID/.

然后,应将整个公用文件夹定义为具有特定唯一名称的工件(此处再次可以使用"$ CI_PIPELINE_ID").

Then the whole public folder should be defined as artifacts with specific unique name (here again "$CI_PIPELINE_ID" can be used).

需要唯一的工件名称,以便在下次执行管道操作时不覆盖工件(如果未指定名称,则默认名称为

Unique name for artifacts is needed to not override the artifacts with the next pipeline execution (if name is not specified, the default name will be taken https://docs.gitlab.com/ee/ci/yaml/#artifactsname).

然后,您可以通过以下链接访问已发布的报告:

Then you can access the published report via the link:

https://yourGitlab/yourNamespace/yourProjectName/{CI_PIPELINE_ID}/index.html

, 这意味着您可以通过更改管道ID来访问所有已保存的报告.

, that means you can access all your saved reports by changing the pipeline id.

我的例子:

stages:
  - publish

cache:
  # Required to keep artifacts from old builds, e.g. from master
  paths:
    - public

pages:
  stage: publish
  script:
    - mkdir -p public
    - mkdir -p public/$CI_PIPELINE_ID/
    - cp target/site/allure-maven-plugin/* public/$CI_PIPELINE_ID/ -R
  artifacts:
    name: "$CI_PIPELINE_ID"
    paths:
      - public
    expire_in: 5 days
  when: always

这篇关于为不同分支机构部署GitLab页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆