SSG NextJS on Gitlab Pages stucked on 404? - gitlab

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!

Related

How to move files from one to second directories on branch during Pipeline run? Gitlab

I have created Docs folder and it should contain report files.
I'm trying to move content from temporary created Allure folder to Docs folder and then copy everything from Docs to public folder to get access to Pages on which that Allure report will be located. I'm doing that process insted of simple copying files from allure folder to public folder to get history about previous runs. Maybe there is some better way to do it ? I'd like to store old reports for some X time (for example for 2 days, to be able to see on ALlure what was wrong is there are some problems) and then delete old ones, not deleting latest which have not reached "deleting point". So, here is my yml file:
stages:
- testing
- deploy
docker_job:
stage: testing
tags:
- docker
image: atools/chrome-headless:java11-node14-latest
before_script:
- npm ci
- npx playwright install
- npm install allure-commandline --save-dev
script: #||true
- npx playwright test
after_script:
- npx allure generate allure-results
rules:
- when: always
allow_failure: true
artifacts:
when: always
paths:
- ./allure-report
expire_in: 1 day
pages:
stage: deploy
script:
- mkdir public
- mv ./allure-report/* Docs
- cp -R ./Docs/* public
artifacts:
paths:
- public
rules:
- when: always
Everything is going good but it doesn't work - mv ./allure-report/* Docs
- cp -R ./Docs/* public are doing nothing or I just can't see any effect. Help me please to correctly solve that problem.
Maybe there is obvious holes in logic, idk, have tried a lot of variants but they all don't work.
Can it be done by my way at all?
okay, so I have done it with "logging in" with my git.conf email/name, then using auth token I did a push of these artifacts to Docs folder, looks like:
stages:
- testing
- deploy
docker_job:
stage: testing
tags:
- docker
image: atools/chrome-headless:java11-node14-latest
before_script:
- npm ci
- npx playwright install
- npm install allure-commandline --save-dev
script: #||true
- npx playwright test
after_script:
- npx allure generate allure-results
rules:
- when: always
allow_failure: true
artifacts:
when: always
paths:
- ./allure-report
expire_in: 15 mins
pages:
stage: deploy
script:
- cp -r -u ./allure-report/* Docs
- cp -R ./Docs/* public
- git config --global user.email "mail"
- git config --global user.name "name"
- git remote set-url origin https://gitlab-ci-token:${token}#gitlab.com/proj_link
- git checkout main
- git add Docs
- git commit -m "assets"
- git push
artifacts:
paths:
- public
rules:
- when: always

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 throw 404 when accessed

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.

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 :)

gitlab-pages: no files (artifacts) to archive, so no website

I'm trying to publish a static website with gitlab-pages. I carefully took inspiration from the official jekyll example to write my own gitlab-ci.yml.
My build succeeds, a ls -l shows that I do have a public/ repository, however I have the message "archiving artifacts… no files to archive" and thus I can't find my website on myusername.gitlab.com/myproject.
I checked that the official example still works. (However… I can't find where it's being published !)
I got no help on irc nor gitter.
Do you have any ideas ? Thanks !
Maybe is it a matter of settings ? The doc states to enable the pages feature but there are hardly any checkboxe to click.
ps: that may be related to https://gitlab.com/gitlab-com/support-forum/issues/456 , which I see was fixed for v8.3.3.
Got it! \o/
.gitlab-ci.yml:
image: python:2.7.11
pages:
cache:
paths:
- vendor
script:
- pip install Lektor
- lektor build --output-path public
artifacts:
paths:
- public
only:
- master
UPDATE
You can also try this:
image: python:2.7
pages:
cache:
paths:
- vendor
stage: deploy
script:
- pip install Lektor
- lektor build --output-path public
artifacts:
paths:
- public
only:
- master
I don't see you need a before_script: command, but if you want that, add to it - pip install Lektor.
I believe the answer to your question is easier that you thought.
Your website will be published at
https://username.gitlab.io/project_name
Got it? It's not gitlab.com! :)
Don't worry, new guides to GitLab Pages are coming soon!

Resources