Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincent15000's avatar

Gitlab CI not working

Hello,

I'm new to using Gitlab CI/CD.

I have this pipeline.

image: node:24.4.1-alpine

stages:
  - build

cache:
  paths:
    - node_modules/

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
  only:
    - main

The job runs successfully, but the build folder isn't replaced by the new one.

Can you help me, please ?

Thanks a lot ;).

V

0 likes
2 replies
LaryAI's avatar
Level 58

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 artifacts to 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!

1 like
vincent15000's avatar

Lary's response seems interesting.

But why isn't it recommended to commit the build outputs ? (I want to commit them on the same repo where the job is executed)

Isn't it a way for automating the updates ?

What I'd like to do is :

  • push update from my local computer on the gitlab

  • from gitlab, execute all needed actions (npm install && npm run build) and commit the build outputs (I can't execute npm run build on the VPS where the application is hosted)

  • pull the updated code on the webhosting in production

  • execute automatically composer install and php artisan optimize

Please or to participate in this conversation.