Jul*_*oro 21 git gitlab gitlab-pages
我正在使用 GitLab Pages 部署我的 React 应用程序,它运行良好。
这是我的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
Run Code Online (Sandbox Code Playgroud)
现在,我刚刚基于我的分支创建了一个开发版本 develop
我想要 2 个版本的 React 应用程序,其中包含 2 个不同的 URL。我怎样才能做到这一点?
例如现在,我有:
my-react-app.com
链接到master
分支
我该如何拥有
dev.my-react-app.com
甚至my-react-app.gitlab.io
链接到develop
分支?
jok*_*oki 22
为此,我已经成功地使用了可浏览的工件。在您的示例中,您将为您的开发分支创建一个作业,并将 设置为发布作业工件PUBLIC_URL
的路径gitlab.io
:
develop:
artifacts:
paths:
- public
environment:
name: Develop
url: "https://$CI_PROJECT_NAMESPACE.gitlab.io/-/$CI_PROJECT_NAME/-/jobs/$CI_JOB_ID/artifacts/public/index.html"
script: |
# whatever
stage: deploy
variables:
PUBLIC_URL: "/-/$CI_PROJECT_NAME/-/jobs/$CI_JOB_ID/artifacts/public"
Run Code Online (Sandbox Code Playgroud)
environment
按照指示设置会在相关合并请求中生成一个 »Review app« 链接,让您只需单击一下即可访问工件。
注意:如果您的存储库在子组中,您需要在上面的两个位置之间插入子组名称/-/
,$CI_PROJECT_NAME
以便生成的 URL 工作。
小智 19
可以为不同的管道/分支发布多个页面。
为此,您需要将页面内容(基本上是测试报告或任何需要发布的内容)复制到公共文件夹中的特定唯一目录。例如,目录的名称可以是管道的 id (CI_PIPELINE_ID)。所以页面源的路径应该是public/$CI_PIPELINE_ID/。
然后整个公共文件夹应该被定义为具有特定唯一名称的工件(这里再次可以使用“$CI_PIPELINE_ID”)。
工件的唯一名称需要在下一次管道执行时不覆盖工件(如果未指定名称,则将采用默认名称https://docs.gitlab.com/ee/ci/yaml/#artifactsname)。
然后您可以通过以下链接访问已发布的报告:
https://yourGitlab/yourNamespace/yourProjectName/{CI_PIPELINE_ID}/index.html
Run Code Online (Sandbox Code Playgroud)
,这意味着您可以通过更改管道 ID 来访问所有已保存的报告。
我的例子:
stages:
- publish
cache:
# Required to keep artifacts from old builds, e.g. from master
paths:
- public
pages:
stage: publish
script:
- 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
Run Code Online (Sandbox Code Playgroud)
每个 GitLab 项目最多可以有一个 Pages 站点。我找不到这方面的明确参考,但文档.gitlab-ci.yml
说:
请注意,页面默认情况下与分支/标签无关,它们的部署完全依赖于您在
.gitlab-ci.yml
. 如果您不pages
使用only
参数限制作业,则每当将新提交推送到任何分支或标签时,页面都将被覆盖。
如果没有only
参数,任何分支的更新都会发布到同一个Pages 站点,覆盖那里的任何内容。使用该only
参数,只有提供的分支才会触发 Pages 构建。
归档时间: |
|
查看次数: |
9390 次 |
最近记录: |