Jenkins pipeline failing to run Chrome headless for Angular tests

I’m having trouble with my Angular project on Jenkins. It works fine locally but fails in the pipeline. The error says it can’t find the Chrome binary for headless testing.

I’ve tried updating Puppeteer and tweaking the karma.conf.ci.js file. I even set the CHROME_BIN location which works for other projects.

Here’s part of the error:

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

My karma.conf file sets up ChromeHeadlessCI with some flags:

customLaunchers: {
  ChromeHeadlessCI: {
    base: 'ChromeHeadless',
    flags: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage'],
  },
},

Any ideas on how to fix this? I’m stumped and could really use some help.

hey ive had this issue b4. try adding these lines to ur jenkinsfile:

sh ‘sudo apt-get update’
sh ‘sudo apt-get install -y chromium-browser’

then set CHROME_BIN in ur karma config:

process.env.CHROME_BIN = ‘/usr/bin/chromium-browser’

this worked 4 me hope it helps!

Have you considered using a Docker container for your Jenkins builds? This approach can solve many environment-related issues, including Chrome installation problems.

You could create a custom Docker image with Chrome pre-installed and use it in your Jenkins pipeline. This ensures a consistent environment across all builds.

Here’s a basic Dockerfile example:

FROM node:14
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | tee /etc/apt/sources.list.d/google-chrome.list
RUN apt-get update && apt-get install -y google-chrome-stable

Then modify your Jenkinsfile to use this Docker image. This method has worked well for me in similar situations, providing a more reliable and reproducible build environment.