1

SOLVED: The issue was a difference in temp directories in the environment. The build was using the temp directories set in buildAgent.properties and the terminal was using the default /tmp directory. Chrome needed the default /tmp to launch properly.

I am experiencing a weird issue when running Angular tests with Karma in TeamCity. I am able to run the tests in the agent's terminal using ng test --watch=false --browsers=ChromeHeadless, but when I run the same exact command in the build steps, it fails with the following error:

13:00:03     23 07 2025 21:00:04.997:INFO [karma-server]: Karma v6.4.4 server started at http://localhost:9876/
13:00:04     23 07 2025 21:00:04.998:INFO [launcher]: Launching browsers ChromeHeadlessNoSandbox with concurrency unlimited
13:00:05     23 07 2025 21:00:05.009:INFO [launcher]: Starting browser ChromeHeadless
13:00:05     23 07 2025 21:00:05.265:ERROR [launcher]: Cannot start ChromeHeadless
13:00:05     
13:00:05     23 07 2025 21:00:05.265:ERROR [launcher]: ChromeHeadless stdout:
13:00:05     23 07 2025 21:00:05.265:ERROR [launcher]: ChromeHeadless stderr:
13:00:05     23 07 2025 21:00:05.273:INFO [launcher]: Trying to start ChromeHeadless again (1/2).
13:00:05     23 07 2025 21:00:05.516:ERROR [launcher]: Cannot start ChromeHeadless
13:00:05     
13:00:05     23 07 2025 21:00:05.516:ERROR [launcher]: ChromeHeadless stdout:
13:00:05     23 07 2025 21:00:05.516:ERROR [launcher]: ChromeHeadless stderr:
13:00:05     23 07 2025 21:00:05.523:INFO [launcher]: Trying to start ChromeHeadless again (2/2).
13:00:05     23 07 2025 21:00:05.770:ERROR [launcher]: Cannot start ChromeHeadless
13:00:05     
13:00:05     23 07 2025 21:00:05.771:ERROR [launcher]: ChromeHeadless stdout:
13:00:05     23 07 2025 21:00:05.771:ERROR [launcher]: ChromeHeadless stderr:
13:00:05     23 07 2025 21:00:05.777:ERROR [launcher]: ChromeHeadless failed 2 times (cannot start). Giving up. 

The environment between the terminal and actual build seem the same to me. I am not sure what's going on. For some reason the build cannot start ChromeHeadless, but the terminal can. Any ideas?

I have tried using xvfb with the following command: xvfb-run -a ng test --watch=false --browsers=ChromeHeadless. This also works in the terminal but not during the build.

I tried configuring my karma file like so, but still no luck (using --browsers ChromeHeadlessNoSandbox):


customLaunchers: {
  ChromeHeadlessNoSandbox: {
    base: 'ChromeHeadless',
    binary: '/usr/bin/google-chrome', // Use the actual path from debug output
    flags: [
      '--no-sandbox',
      '--disable-gpu',
      '--disable-dev-shm-usage',
      '--disable-setuid-sandbox'
    ]
  }
},

2
  • Hello Joe Vogel, welcome to StackOverflow. This question is now visible to everyone and can be answered. You mentioned in comments that you found the problem. I encourage you to answer your own question and post it here for future visitors. Commented Jul 24 at 5:08
  • The issue was a difference in temp directories in the environment. The build was using the temp directories set in buildAgent.properties and the terminal was using the default /tmp directory. Chrome needed the default /tmp to launch. Commented Jul 24 at 15:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.