Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to activate GitLab Pages in an existing project?

Tags:

gitlab

I want to publish my code coverage reports for my Java project that is already on GitLab. I generate code coverage reports with JaCoCo in a folder located in app/target/site/jacoco/.

I saw I had to activate GitLab Pages. But this link on the GitLab documentation say I have to create a new project. My Java project is already in a GitLab Project and I don't know how to do in that case.

like image 669
Nicryc Avatar asked Apr 17 '19 16:04

Nicryc


People also ask

Where is my GitLab pages URL?

Your project's URL is https://gitlab.com/websites/websites.gitlab.io . Once you enable GitLab Pages for your project, your website is published under https://websites.gitlab.io . General example: On GitLab.com, a project site is always available under https://namespace.gitlab.io/project-name.

How do I enable GitLab?

Sign in to your GitLab self-managed instance. On the top bar, select Main menu > Admin. On the left sidebar, select Subscription. Paste the activation code in Activation code.

Are GitLab pages free?

With GitLab Pages you can host your static website for free.


1 Answers

You do not have to create a new project if you already got one

The GitLab documentation is a little confusing about this. What the documentation means is you can get started with your Pages configuration by using an existing one of another template project. It does not mean you can only use GitLab Pages with new projects.

To use GitLab pages in your project, place a .gitlab-ci.yml in the root directory of your repository. Here, you can specify how the content of your GitLab Pages site should be generated and published, e.g.

pages:
  stage: deploy
  script:
  - mkdir .public
  - cp -r * .public
  - mv .public public
  artifacts:
    paths:
    - public
  only:
  - master

Source: https://about.gitlab.com/2016/04/07/gitlab-pages-setup/#add-gitlab-ci

TL,DR The GitLab Pages configuration is defined in your CI/CD configuration file (.gitlab-ci.yml). You can add or change this file at any point, not only when you create a new project.


Edit:
The published static content has to be in the public folder in the root of your project. There is no way around that. However, this is not a problem, you can simply move your stuff there during CI/CD, you do not need to change the repository content itself.

If you want to publish app/target/site/jacoco, you can do:

pages:
  stage: deploy
  script:
  - mv app/target/site/jacoco/ public
  artifacts:
    paths:
    - public
  only:
  - master
like image 96
Thomas Kainrad Avatar answered Oct 05 '22 08:10

Thomas Kainrad