Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic job (phpunit with code coverage) when jenkins is idle?

My jenkins install is working properly just that the phpunit+coverage on my code takes 5 minutes finish - because of too many files.

For me, it's too much wait for just knowing if my last commit broke the build or not.

Is there a way I can run a special build (or scheduled) when jenkins is idle and while only in that build it will create phpunit code coverage reports?

I could run phpunit -c with-coverage.xml in cron but that is isolated from jenkins, it does not refresh jenkin's job home page.

like image 498
thevikas Avatar asked Jan 17 '23 21:01

thevikas


2 Answers

This is a common general problem: you want a first-tier build to quickly tell you if you've broken the application and a second-tier build to perform deeper analysis. Things that take more time in this latter build include

  • Code coverage
  • Static analysis (code duplication and complexity)
  • API documentation

You can achieve this using two separate Jenkins projects--each executing an appropriate Ant task--where the second build is dependent on the first build's success. I believe you can even have the first-tier build pass artifacts (e.g. junit.xml) to the second-tier build, but I haven't had the time to experiment with this yet.

Unfortunately, this is a half-answer. I know you can do it, but I haven't done it myself, nor can I tell you step-by-step how to do it. Hopefully this gives you enough pointers to get you started.

like image 137
David Harkness Avatar answered Jan 20 '23 10:01

David Harkness


If you are using ant to orchestrate your build maybe you don't even need a two-tier build but you can use tell Jenkins/Ant to stop when your tests fail as you usually don't really care about metrics when you break the build.

What I tend to use is:

 <target name="phpunit" description="Run unit tests with PHPUnit">
  <exec executable="phpunit" failonerror="true"/>
 </target>

as on of the first build targets. It will try to generate code-coverage so the phpunit run takes a littler longer but you don't have to spend time to generate all the metrics.


If you want it really fast:

You can tell Jenkins to have a "post build action" that starts another build when your 'run tests' build succeeded. You can even set it up to wait half an hour or so to start the "Metrics" build just in case you do 3-4 commits and don't want the metric build to start immediately after the first one worked out

like image 35
edorian Avatar answered Jan 20 '23 10:01

edorian