1

I have a private repo for which I would like to set up a staging area and have it deploy when pushing to dev branch.

This is my .gitlab-ci.yml now

image: alpine:latest

pages:
  stage: deploy
  script:
  - echo 'Nothing to do...'
  artifacts:
    paths:
    - public
  only:
  - master

review:
  stage: deploy
  script: |
    # Nothing
  artifacts:
    paths:
    - public
  environment:
    name: Review
    url: "https://$CI_PROJECT_NAMESPACE.gitlab.io/-/$CI_PROJECT_NAME/-/jobs/$CI_JOB_ID/artifacts/public/index.html"
  variables:
    PUBLIC_URL: "/-/$CI_PROJECT_NAME/-/jobs/$CI_JOB_ID/artifacts/public"

When logged into GitLab I can see the job artifacts at https://$CI_PROJECT_NAMESPACE.gitlab.io/-/$CI_PROJECT_NAME/-/jobs/$CI_JOB_ID/artifacts/public/index.html. But logged out / external users can't see this URl. They're redirected to a login page.

The docs seem to indicate this is because the project is set to private: For private projects, to all project members (Guest or higher)

Is there a way to set up a publicly accessible staging area on a private GitLab Pages repo? Or do I have to make the repo public?

Leeroy
  • 2,003
  • 1
  • 15
  • 21

1 Answers1

2

Yes, you can set the "pages" function to be public while the repository itself remains private. To do so, go to Settings > General, then set Project visibility to private, and set Pages to Everyone.

Patrick
  • 2,885
  • 1
  • 14
  • 20
  • It's already set like this. But external users can't see the staging area, meaning the browsable artifacts resulting from the Review environment, which get built on push to `dev` branch – Leeroy Oct 20 '21 at 09:19
  • Ah, sorry, I misunderstood what you were asking about when you mentioned staging area. Your link is not really part of "pages", it's just the artifact of a CI/CD job. You must be logged into view CI/CD artifacts. It's only when those artifacts are published to the "pages" piece that they can be publicly viewed. – Patrick Oct 21 '21 at 03:33
  • I see. So how should I go about setting up a staging area for a Gitlab Pages site so it doesn't get indexed by search engines but is publicly accessible if you have the link? – Leeroy Oct 21 '21 at 15:31
  • There isn't really the concept of a 'staging' area that's publicly accessible, but you could potentially set up a second project to act as a staging domain. However, you'd only have one project for stage, you couldn't deploy and test from each MR. As to your search engine questions, if you want something to not be indexed by a search engine, check out robots.txt. – Patrick Oct 21 '21 at 23:34