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

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


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.


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