I have a small Storybook project that is hosted on Gitlab. I use Gitlab pages to host the storybook. The project builds at folder called storybook-static and then the files from this folder are served through gitlab pages.
I'm trying to make the pipeline so I can have three subfolders: latest, nextandtest` as follows:
- When tag is created, the build files are moved to
public/latest - When MR is merged, the build files are moved to
public/next - When manually triggered, the build files are moved to
public/test.
The three subdirectories co-exists, so updating public/latest does not affect public/test
.gitlab-ci.yml:
image: node:16-alpine
stages:
- build
- deploy
cache:
paths:
- node_modules/
before_script:
- npm ci --legacy-peer-deps
build-and-deploy-latest:
stage: build
script:
- npm run build:storybook -c .storybook
- rm -rf public/latest
- mkdir -p public/latest
- cp -r storybook-static/* public/latest
artifacts:
paths:
- public
rules:
- if: '$CI_COMMIT_TAG'
build-and-deploy-next:
stage: build
script:
- npm run build:storybook -c .storybook
- rm -rf public/next
- mkdir -p public/next
- cp -r storybook-static/* public/next
artifacts:
paths:
- public
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_EVENT_TYPE == "merge"'
build-and-deploy-test:
stage: build
script:
- npm run build:storybook -c .storybook
- rm -rf public/test
- mkdir -p public/test
- cp -r storybook-static/* public/test
artifacts:
paths:
- public
when: manual
only:
- merge_requests
The pipelines are triggered on the right events. I can see from the logs that the build is successful. When I browse the artifacts, I can see the files ( ex. public/latest/index.html ) exists. When I download the folder with the artifacts and spin static server locally, it serves the index.html.
But opening the gitlab pages /next , /latest or /test gives me 404. I waited a day ( in case if it was cache, or runner needed time, etc ) and I still see 404s.