Certainly! Your GitLab CI job appears to run successfully, but the changes to the build folder are not reflected in your repository after the pipeline finishes. This is a common point of confusion for those new to CI/CD.
Key Point:
GitLab CI jobs run in isolated environments (runners). Any file changes made during the job (like your new public/build folder) exist only in that job's environment. They are not automatically pushed back to your repository.
What Can You Do?
1. If you want to use the build artifacts in later jobs or download them:
You should use the artifacts keyword to save the build output:
build:
stage: build
script:
- rm -rf public/build-tmp
- npm ci
- npm run build -- --outDir=public/build-tmp
- rm -rf public/build
- mv public/build-tmp public/build
artifacts:
paths:
- public/build
only:
- main
This will make the public/build folder available as a downloadable artifact after the job finishes, and also available to subsequent jobs in the pipeline.
2. If you want to commit the build output back to your repository:
This is less common (and generally not recommended for build outputs), but if you really want to commit the built files back to your repo, you need to add a job that pushes the changes. For this, you need to set up a CI job with a Git user and a CI/CD variable with write access (like a personal access token).
Example:
build-and-commit:
stage: build
image: node:24.4.1-alpine
script:
- apk add --no-cache git
- rm -rf public/build-tmp
- npm ci
- npm run build -- --outDir=public/build-tmp
- rm -rf public/build
- mv public/build-tmp public/build
- git config --global user.email "[email protected]"
- git config --global user.name "CI Bot"
- git add public/build
- git commit -m "Update build output [ci skip]" || echo "No changes to commit"
- git push https://<YOUR_GITLAB_TOKEN>@gitlab.com/<YOUR_USERNAME>/<YOUR_REPO>.git HEAD:main
only:
- main
Replace <YOUR_GITLAB_TOKEN>, <YOUR_USERNAME>, and <YOUR_REPO> with your actual values.
Store your token in a CI/CD variable for security.
Summary:
- Changes in the CI job are not reflected in your repo unless you explicitly push them.
- Use
artifactsto pass build outputs between jobs or download them. - Only push build outputs to your repo if you have a specific reason.
Let me know if you need help with any of these steps!