Gitlab Pages throw 404 when accessed - gitlab

I have a group project with the following name (hosted in Gitlab): gitlab.com/my-group/my-project.
I have generated coverage reports during testing and saved them as artifacts using Gitlab CI. Here is Gitlab CI config:
test:
stage: test
image: node:11
before_script:
- npm install -g yarn
- yarn
cache:
paths:
- node_modules/
script:
- yarn lint
- yarn test --all --coverage src/
except:
- tags
artifacts:
paths:
- coverage/
coverage: '/Statements\s+\:\s+(\d+\.\d+)%/'
deploy-pages:
stage: deploy
dependencies:
- test
script:
- mv coverage/ public/
artifacts:
paths:
- public/
expire_in: 30 days
except:
- tags
When I open deploy stage job, I can see the artifact being created. Here is the screenshot: . All the files are under /public directory in the artifact.
Now, when I go to: https://my-group.gitlab.io/my-project, I keep getting 404.
I am not sure what step I am missing here. Can someone shed some light on this issue for me?
Thanks!

There are three basic requirements for the project itself:
project must be named group.gitlab.io (if you want it to be the base domain)
job must create artifact in public directory
job must be called pages
Most likely it's the last one that needs fixing since your job is currently called deploy-pages. Simply rename that to pages.
You'll know when you got everything working because under Settings > Pages, it will tell you the link where it's published to.

Related

Gitlab-CI avoid unnecessary rebuilds of react portion of project

I have a stage in my CI pipeline (gitlab-ci) as follows:
build_node:
stage: Build Prerequisites
only:
- staging
- production
- ci
image: node:15.5.0
artifacts:
paths:
- http
cache:
key: "node_modules"
paths:
- ui/node_modules
script:
- cd ui
- yarn install --network-timeout 600000
- CI=false yarn build
- mv build ../http
The UI however, is not the only part of the project. There are other files with their own build processes. So whenever we commit changes for only those other files, this stage gets rerun every time, even if nothing in the ui folder changed.
Is there a way to have gitlab cache or otherwise not rebuild this every time if there were no changes? Any changes that should trigger a rebuild would all be under the ui folder. Just have it use the older build if possible?
It is possible to do in latest Gitlab version using the rules:changes keyword.
rules:
- changes:
- ui/*
Link: https://docs.gitlab.com/ee/ci/jobs/job_control.html#variables-in-ruleschanges
This will only check for changes inside the ui folder and trigger this stage.
Check this link for more info: https://docs.gitlab.com/ee/ci/yaml/#ruleschanges

SSG NextJS on Gitlab Pages stucked on 404?

I started a simple SSG NextJS project to build my personal website/portfolio: https://gitlab.com/soykje/soykje.gitlab.io, that I want to deploy using Gitlab pages (but without the now stuff...).
I created the .gitlab-ci.yml and updated the next.config.js to take care of assetPrefix parameter, but still I'm getting a mysterious 404. And I can't find a way to fix it, as the CI/CD tells everything is fine... :(
Here is my .gitlab-ci.yml:
image: node
cache:
paths:
- node_modules
before_script:
- npm install
pages:
script:
- npm run publish # eq. to "next build && next export"
- mv out public
artifacts:
paths:
- public
only:
- master
Did anyone encounter the same issue deploying a static NextJS project using Gitlab Pages? Any help would be great, thx in advance!
Ok I found the reason: I was not using the mv command properly... So finally I ended up with the following config, and everything runs fine:
image: node
before_script:
- npm install
cache:
paths:
- node_modules
pages:
script:
- npm run publish
- mv out/* public
- rm -rf out
artifacts:
paths:
- public
only:
- master
Hope that will help!

How do I deploy a sapper/svelte site to Gitlab Pages?

I am trying to use gitlab pages to host my static site generated by Sapper and Svelte.
I used the sapper starter app from the getting started docs:
npx degit "sveltejs/sapper-template#rollup" my-app
I added the .gitlab-ci.yml file as gitlab docs instrcuted:
# This file is a template, and might need editing before it works on your project.
image: node:latest
# This folder is cached between builds
# http://docs.gitlab.com/ce/ci/yaml/README.html#cache
cache:
paths:
- node_modules/
pages:
stage: deploy
script:
- npm run export
- mkdir public
- mv __sapper__/export public
artifacts:
paths:
- public
only:
- master
When the pipeline runs, it says it passes, but I still get a 404 error even after a day of waiting.
Has anyone successfully done this with sapper??
You're moving the export folder, rather than its contents. Change your move command to
mv __sapper__/export/* public/
so that your config would be
# This file is a template, and might need editing before it works on your project.
image: node:latest
# This folder is cached between builds
# http://docs.gitlab.com/ce/ci/yaml/README.html#cache
cache:
paths:
- node_modules/
pages:
stage: deploy
script:
- npm run export
- mkdir public
- mv __sapper__/export/* public/
artifacts:
paths:
- public
only:
- master

GitLab Pages, docs generated with sphinx

I want to host static page generated with Sphinx on GitLab Pages. Built index.html file is in:
project/docs/build/html
How .gitlab-ci.yml should look like to deploy the page? I have something like that and it isn't working:
pages:
stage: deploy
script:
- echo 'Nothing to do...'
artifacts:
paths:
- docs/build/html
only:
- master
According to the documentation for .gitlab-ci.yml, the pages job has special rules it must follow:
Any static content must be placed under a public/ directory
artifacts with a path to the public/ directory must be defined
So the example .gitlab-ci.yml you gave would look something like this:
pages:
stage: deploy
script:
- mv docs/build/html/ public/
artifacts:
paths:
- public
only:
- master
And of course, if you don't want to move the html folder for whatever reason, you can copy it instead.
For further reference, an example sphinx project for GitLab Pages was pushed around the time you originally posted this question.
image: python:3.10-alpine
stages:
- deploy
pages:
tags:
- sphinx
stage: deploy
script:
- python3 -m pip install sphinx furo
- sphinx-build -b html docs/source/ public/
artifacts:
paths:
- public
only:
- main # 'master' was renamed to 'main'
This is what my GitLab-ci.yml looks like.
On a side note: You don't need a public-folder in your repository. GitLab itself will handle it. I installed furo as theme (make sure to change the conf.py accordingly) to make it look nicer.

Gitlab CI not invoking the 'pages' job

I have a project hosted on Gitlab. The project website is inside the pages branch and is a jekyll based site.
My .gitlab-ci.yml looks like
pages:
script:
- gem install jekyll
- jekyll build -d public/
artifacts:
paths:
- public
only:
- pages
image: node:latest
cache:
paths:
- node_modules/
before_script:
- npm install -g gulp-cli
- npm install
test:
script:
- gulp test
When I pushed this configuration file to master, the pipeline executed only the test job and not pages job. I thought maybe pushing to master didn't invoke this job because only specifies pages branch. Then I tried pushing to pages branch but to no avail.
How can I trigger the pages job?
You're right to assume that the only constraint makes the job run only on the ref's or branches specified in the only clause.
See https://docs.gitlab.com/ce/ci/yaml/README.html#only-and-except
It could be that there's a conflict because the branch and the job have the same name. Could you try renaming the job to something different just to test?
I'd try a couple of things.
First, I'd put in this stages snippet at the top of the YML:
stages:
- test
- pages
This explicitly tells the CI to run the pages stage after the test stage is successful.
If that doesn't work, then, I'd remove the only tag and see what happens.
Complementing #rex answer's:
You can do either:
pages:
script:
- gem install jekyll
- jekyll build -d public/
artifacts:
paths:
- public
Which will deploy your site regardless the branch name, or:
pages:
script:
- gem install jekyll
- jekyll build -d public/
artifacts:
paths:
- public
only:
- master # or whatever branch you want to deploy Pages from
Which will deploy Pages from master.
Pls let me know if this helps :)

Resources