I'm learning about GitLab ci. There is my pipeline code. enter image description here
There was the result. I have already ensured all the variables are right. enter image description here
There is my root directory enter image description here
I guess there must be the yarn serve default configuration
I just started the serve. There is nothing change. Maybe someone can tell me why.
stages:
- build
- test
- deploy staging
- deploy production
variables:
APP_VERSION: $CI_PIPELINE_IID
VERSION_PATH: version.html
build website:
image: node:16-alpine
stage: build
script:
- yarn install
- yarn lint
- yarn test
- yarn build
- echo $APP_VERSION > build/version.html
artifacts:
paths:
- build
test index:
image: node:16-alpine
stage: test
script:
- yarn global add serve
- apk add curl
- serve -s build &
- sleep 10
- curl http://localhost:3000 | grep 'React App'
# - curl http://localhost:3000/$VERSION_PATH | grep $APP_VERSION
It has nothing to do with GitLab CI configuration, you are doing everything as should be you have clearly defined the stages, the problem however is you are using
the
-s
option is made for serving single-page applications, that is it will always return theindex.html
on each request, it will not return any other page, so your version.html will not get served.Change it from
serve -s build
toas you can see when I made a request to
version.html
it gave me a301
status and redirected me to/version
however, when I run it without the
-s
option it returns multiple pages ( status 200)so run
serve
without-s
option