ChromeHeadless binary not found when running tests in Jenkins CI pipeline

Chrome Binary Missing in Jenkins Build

I’m having trouble with my CI pipeline after updating to Node 18. My Vue project works perfectly when I run tests locally, but Jenkins keeps failing with a Chrome binary error.

The Error I’m Getting

When Jenkins tries to run the test suite, it throws this error:

Cannot start ChromeHeadless
Can not find the binary /home/jenkins/.cache/puppeteer/chrome/linux-134.0.6998.35/chrome-linux64/chrome
Please set env variable CHROME_BIN

My Current Setup

Here’s my karma configuration file:

process.env.CHROME_BIN = require('puppeteer').executablePath()

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-coverage')
    ],
    browsers: ['HeadlessChrome'],
    customLaunchers: {
      HeadlessChrome: {
        base: 'ChromeHeadless',
        flags: [
          '--no-sandbox',
          '--disable-web-security',
          '--disable-gpu'
        ]
      }
    },
    coverageReporter: {
      dir: require('path').join(__dirname, './coverage'),
      subdir: '.',
      reporters: [
        { type: 'html' },
        { type: 'text-summary' }
      ]
    },
    reporters: ['progress', 'coverage'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    singleRun: true
  });
};

I’ve tried updating puppeteer to the latest version and setting the CHROME_BIN environment variable manually, but nothing seems to work. The same configuration works fine on other projects using the old Jenkins setup.

Has anyone encountered this issue before? Any suggestions on how to fix the Chrome binary path problem in Jenkins?

I experienced similar issues after upgrading Node in my CI pipeline. This typically occurs when Chrome isn’t installed globally in the Jenkins environment or if the Puppeteer-installed version becomes corrupted. To resolve this, I recommend foregoing Puppeteer’s bundled Chrome and instead install Chrome directly in your Jenkins container. You can achieve this by adding apt-get update && apt-get install -y google-chrome-stable to your Dockerfile or setup script. Additionally, make sure to set the environment variable CHROME_BIN to /usr/bin/google-chrome. This approach is generally more stable than relying on Puppeteer’s cached version, which can be cleared between builds, and ensure that the Jenkins user has access to the Chrome binary.

Hit this same issue after our Jenkins agents got updated. The problem is Jenkins wipes Puppeteer’s cache directory between builds in most setups. I fixed it by using the system Chrome instead of Puppeteer’s downloaded version. Make sure Chrome’s installed on your Jenkins node, then set the path in your karma config: process.env.CHROME_BIN = '/usr/bin/google-chrome' or process.env.CHROME_BIN = '/usr/bin/chromium-browser' depending on what you have. You can check which Chrome binary exists by adding a shell step that runs which google-chrome or which chromium-browser. Way more reliable than depending on Puppeteer’s cache.

Same headache here! Add --disable-dev-shm-usage to your Chrome flags in karma config. Jenkins containers usually have limited shared memory, so Chrome fails even when the binary’s there. Also check if your Jenkins user can actually execute the Chrome binary - that’s bitten me before.