Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Karma cannot launch Chrome for Jenkins in Ubuntu 12.04

I am trying to run karma as a grunt task on a Ubuntu 12.04 machine in Jenkins CI. The issue I am running into is that karma will not open Chrome and gives the following error:

Started by GitHub push by spencerapplegate
[EnvInject] - Loading node environment variables.
Building in workspace /var/lib/jenkins/jobs/rescour-roomba master/workspace
Checkout:workspace / /var/lib/jenkins/jobs/rescour-roomba master/workspace - hudson.remoting.LocalChannel@7b41ce14
Using strategy: Default
Last Built Revision: Revision ee61ceea1b8728e90b01db04a1813284a524caed (origin/master)
Fetching changes from 1 remote Git repository
Fetching upstream changes from origin
Commencing build of Revision d3ed5ffd7c7b7a707bd9310c5bce09242e1faced (origin/master)
Checking out Revision d3ed5ffd7c7b7a707bd9310c5bce09242e1faced (origin/master)
[EnvInject] - Executing scripts and injecting environment variables after the SCM step.
[EnvInject] - Injecting as environment variables the properties content
CHROME_BIN=/opt/google/chrome/

[EnvInject] - Variables injected successfully.
[workspace] $ /bin/sh -xe /tmp/hudson5570746814297674358.sh
+ sudo npm install
+ sudo grunt buildProd
Loading "express.js" tasks...
[31mERROR[39m[31m>> [39mError: Cannot find module 'temp'

[4mRunning "clean:build" (clean) task[24m
Cleaning ".tmp"...[32mOK[39m
Cleaning "build/app"...[32mOK[39m
Cleaning "build/app-config"...[32mOK[39m
Cleaning "build/components"...[32mOK[39m
Cleaning "build/img"...[32mOK[39m
Cleaning "build/index.html"...[32mOK[39m
Cleaning "build/scripts"...[32mOK[39m
Cleaning "build/src"...[32mOK[39m
Cleaning "build/styles"...[32mOK[39m

[4mRunning "copy:local" (copy) task[24m
Created [36m370[39m directories, copied [36m2260[39m files

[4mRunning "compass:prod" (compass) task[24m
[31m[0m[32mdirectory[0m .tmp/styles/ 
[31m[0m[32m   create[0m .tmp/styles/main.css (1.732s)
Compilation took 1.784s

[4mRunning "template:prod" (template) task[24m

[4mRunning "clean:template" (clean) task[24m
Cleaning ".tmp/index.html.template"...[32mOK[39m

[4mRunning "karma:unit" (karma) task[24m
[36m[2013-10-07 10:07:51.709] [DEBUG] config - [39mautoWatch set to false, because of singleRun
[32mINFO [karma]: [39mKarma server started at http://localhost:8079/
[32mINFO [launcher]: [39mStarting browser Chrome
[31mERROR [launcher]: [39mCannot start Chrome        

[32mINFO [launcher]: [39mTrying to start Chrome again.
[31mERROR [launcher]: [39mCannot start Chrome        

[32mINFO [launcher]: [39mTrying to start Chrome again.
[31mERROR [launcher]: [39mCannot start Chrome        

[33mWarning: Task "karma:unit" failed. Use --force to continue.[39m

[31mAborted due to warnings.[39m
Build step 'Execute shell' marked build as failure
SSH: Current build result is [FAILURE], not going to run. 
Finished: FAILURE

I have set CHROME_BIN=/opt/google/chrome and it seems like it has no issue finding the executable.

Other approaches I have taken (all unsuccessful) are: -> Create shell script to open chrome as root with flag --user-data-dir -> Copy all chrome files to a jenkins subdirectory /home/jenkins/opt/google/chrome -> Change ownership of all chrome files in /opt/google/chrome to jenkins

The other oddity is that when I log into the machine as the jenkins user, chrome runs the tests fine.

Please let me know if there is any more info I need to provide. Thanks

like image 378
Spencer Applegate Avatar asked Nov 23 '25 05:11

Spencer Applegate


2 Answers

I had the same problem. After install xvnc plugin for Jenkins (https://wiki.jenkins-ci.org/display/JENKINS/Xvnc+Plugin), problem disappeared.

like image 57
Lehu Avatar answered Nov 27 '25 00:11

Lehu


For me, it was a misuse of karma start vs karma run. You need to have a karma server running, and use karma run in the jenkins job. See my question and answer here.

Edit: Lehu's answer works for both start/run.

like image 31
IanBussieres Avatar answered Nov 26 '25 23:11

IanBussieres



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!