I've upgraded my Angular project, which meant I needed to make a Jenkins agent use Node 18 to work with it.
The project builds and tests fine locally without issues. However, once I try running this through my Jenkins pipeline, I get this error:
Task :testUnit
[email protected] test:ci
ng test --code-coverage --configuration=ci --no-watch --browsers=ChromeHeadless authentication
Generating browser application bundles (phase: setup)... Browser application bundle generation complete.
12 03 2025 14:47:00.673:WARN [filelist]: Pattern "/home/ec2-user/workspace/ibrary_authentication_angular_15/polyfills.js" does not match any file. 12 03 2025 14:47:00.700:WARN [filelist]: Pattern "/home/ec2-user/workspace/ibrary_authentication_angular_15/polyfills.js" does not match any file.
12 03 2025 14:47:00.707:INFO [karma-server]: Karma v6.4.4 server started at http://localhost:9876/
12 03 2025 14:47:00.707:INFO [launcher]: Launching browsers ChromeHeadless with concurrency unlimited
12 03 2025 14:47:00.716:INFO [launcher]: Starting browser ChromeHeadless 12 03 2025 14:47:00.724:ERROR [launcher]: 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
12 03 2025 14:47:00.724:ERROR [launcher]: ChromeHeadless stdout: 12 03 2025 14:47:00.724:ERROR [launcher]: ChromeHeadless stderr:
✔ Browser application bundle generation complete. ✔ Browser application bundle generation complete.
Task :testUnit FAILED
FAILURE: Build failed with an exception.
- What went wrong: Execution failed for task ':testUnit'.
Process 'command 'npm'' finished with non-zero exit value 1
I've tried upgrading puppetteer and making a custom chrome headless browser in the karma.conf.ci.js which is used by jenkins. It also states the CHROME_BIN location which works on other projects in the older jenkins pipeline.
Here is my Karma.conf for reference:
// Karma configuration file, see link for more information
// .0/config/configuration-file.html
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-jasmine-html-reporter'),
require('karma-junit-reporter'),
require('karma-coverage-istanbul-reporter'),
require('karma-sonarqube-unit-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../../coverage'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
},
junitReporter: {
outputDir: '../../test-results',
outputFile: 'test-results.xml',
},
sonarQubeUnitReporter: {
outputFile: '../../reports/ut_report.xml',
overrideTestDescription: true,
testPath: './projects/authentication/src',
testPaths: ['./projects/authentication/src'],
testFilePattern: '.spec.ts',
useBrowserName: false
},
reporters: ['progress', 'kjhtml', 'junit', 'coverage-istanbul', 'sonarqubeUnit'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['ChromeHeadlessCI'],
customLaunchers: {
ChromeHeadlessCI: {
base: 'ChromeHeadless',
flags: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage'],
},
}, singleRun: true,
restartOnFileChange: true,
files: [
require('path').join(__dirname, '../../polyfills.js')
]
});
};
If anyone has any idea of what is wrong or how I can get around this it would be really helpful