有没有一种方法可以使用gitlab/gh页面在一个存储店中在每个分支中创建不同的网页?

发布于 2025-02-05 20:41:37 字数 176 浏览 3 评论 0原文

我想弄清楚使用gitlab或gh页面的一个回购是否可以使用每个分支机构创建不同的网页。在这一点上,我愿意在两者之间切换,因为这是我真正想做的事情。我发现了依赖缓存的解决方案,我希望这能摆脱这种解决方案。我已经对此感到困惑了一段时间,并在Gitlab上尝试了多种解决方案,但尚未通过GH页面尝试任何内容。

任何帮助将不胜感激!

I'd like to figure out if it's possible to create different web pages per each branch using one repo either using GitLab or gh-pages. At this point, I am willing to switch between both since this is something I'd really like to do. I have found solutions that are reliant on cache, which I would hope to move away from. I have been stumped on this for a while and have tried multiple solutions on GitLab, but have yet to try anything via gh-pages.

Any help would be appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月亮是我掰弯的 2025-02-12 20:41:37

这些平台上只有一个站点。您不能有单独的站点用于单独的分支。

您可以在没有某种缓存/文物检索的情况下进行此操作的唯一方法(正如您提到的是问题中的另一种选择)是在发布页面网站时立即建立所有分支。

如何完全取决于许多因素,包括您用来构建网站的工具以及它们是否与上下文相关 - 但它可能看起来像这样的东西Gitlab

pages:
  # fetch the whole repo
  # this logic can change if you're on a detached head, like an MR
  # so we account for that here
  before_script: | 
        if [[ -n "$CI_COMMIT_BRANCH" ]]; then  # branch pipelines
            git remote set-url origin "https://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git"
            git fetch origin
            git checkout $CI_COMMIT_BRANCH
        fi
        if [[ -n "$CI_MERGE_REQUEST_IID" ]]; then  # MR pipelines
            git remote set-url origin "https://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_HOST}/${CI_MERGE_REQUEST_SOURCE_PROJECT_PATH}.git"
            git fetch origin
        fi
  script: |
        mkdir public
        branches=()
        # ref: https://stackoverflow.com/a/3847586/5747944
        eval "$(git for-each-ref --shell --format='branches+=(%(refname))' refs/heads/)"
        for branch in "${branches[@]}"; do
            git checkout "$branch"
            # build each branch and output to public directory
            # YOU implement this
            make build "$branch" -o "public/${branch}"
        done
  artifacts:
    paths:
      - public
  environment: # ensure outdated jobs are skipped
    name: pages # https://docs.gitlab.com/ee/ci/environments/deployment_safety.html#skip-outdated-deployment-jobs

Only one site is supported on these platforms. You cannot have separate sites for separate branches.

The only way you might do this without some sort of cache/artifact retrieval (as you mentioned is another option in your question) is to build all your branches at once when publishing your Pages site.

How exactly you do that depends on a lot of factors, including what tool(s) you're using to build your site and if they are context-dependent -- but it might look something like this in GitLab

pages:
  # fetch the whole repo
  # this logic can change if you're on a detached head, like an MR
  # so we account for that here
  before_script: | 
        if [[ -n "$CI_COMMIT_BRANCH" ]]; then  # branch pipelines
            git remote set-url origin "https://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git"
            git fetch origin
            git checkout $CI_COMMIT_BRANCH
        fi
        if [[ -n "$CI_MERGE_REQUEST_IID" ]]; then  # MR pipelines
            git remote set-url origin "https://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_HOST}/${CI_MERGE_REQUEST_SOURCE_PROJECT_PATH}.git"
            git fetch origin
        fi
  script: |
        mkdir public
        branches=()
        # ref: https://stackoverflow.com/a/3847586/5747944
        eval "$(git for-each-ref --shell --format='branches+=(%(refname))' refs/heads/)"
        for branch in "${branches[@]}"; do
            git checkout "$branch"
            # build each branch and output to public directory
            # YOU implement this
            make build "$branch" -o "public/${branch}"
        done
  artifacts:
    paths:
      - public
  environment: # ensure outdated jobs are skipped
    name: pages # https://docs.gitlab.com/ee/ci/environments/deployment_safety.html#skip-outdated-deployment-jobs
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文