Skip to main content
In this guide, you’ll learn how to configure and optimize a CI/CD pipeline on a self-hosted GitLab Runner using the Shell executor. We’ll walk through:
  1. Defining a basic pipeline.
  2. Selecting your self-managed runner with tags.
  3. Troubleshooting shell-profile issues.
  4. Installing Node.js on the runner VM.
  5. Caching npm dependencies between runs.
  6. Customizing the runner’s cache directory.

1. Basic Pipeline Configuration

Begin by creating a simple .gitlab-ci.yml that runs unit tests against your Node.js project. This example sets up environment variables, uses stages, and caches node_modules to speed up subsequent runs.

2. Selecting the Self-Managed Runner

To ensure jobs land on your Shell executor, add the same tags you used during runner registration:
Runner tags must match exactly (case-sensitive). Review Settings > CI/CD > Runners in your project to confirm tag names.
Your project’s CI/CD settings should display your tagged runner:
The image shows the CI/CD settings page of a GitLab project, with options for configuring pipelines, Auto DevOps, runners, artifacts, variables, and pipeline trigger tokens. The interface includes a sidebar with various settings categories.
After committing these changes, GitLab will automatically trigger a new pipeline.

3. Troubleshooting Shell-Executor Profiles

If the job fails during prepare environment, you might see:
The image shows a GitLab CI/CD job interface where a unit testing job has failed, with an error message related to preparing the environment.
This usually means your shell’s logout or profile scripts are clearing the console. On the runner VM, edit ~/.bash_logout:
Comment out any clear_console lines, commit the update, and rerun the pipeline.
Modifying shell profiles on production runners can affect all jobs. Always back up files before editing.

4. Installing Node.js on the Runner

Since the Shell executor uses your VM’s environment, you must install Node.js globally:
Verify:
Rerun your pipeline—npm install and npm test should now succeed.

5. Caching Dependencies for Faster Builds

Your pipeline’s cache settings will automatically save node_modules on success:
Inspect the runner’s cache directory:
On future runs, the cache is restored:

6. Customizing the Runner’s Cache Directory

By default, caches live under GitLab Runner’s home folder. To change it, update /etc/gitlab-runner/config.toml:
Restart the service:
Subsequent cache archives will appear under your new cache_dir:
The image shows a GitLab documentation page about advanced configuration settings for runners, with a focus on cache directories. The page includes a list of settings and descriptions, and a sidebar with navigation links.
For a deep dive into advanced runner settings, consult the official docs:
The image shows a GitLab documentation page about advanced configuration for GitLab Runner, detailing how to modify the config.toml file and explaining configuration validation.

Watch Video