Using Jenkins and Php Code Sniffer

六眼飞鱼酱① 提交于 2019-12-02 00:34:21

问题


I'm trying to use the Php Code Sniffer plugin in Jenkins. It generates a checkstyle.xml file but there are no errors inside, and I know that I should have.

Here's the containt of my checkstyle.xml :

<?xml version="1.0" encoding="UTF-8"?>
<checkstyle version="1.5.0RC2">
</checkstyle>

My build.xml file for Jenkins is :

<target name="phpcs" >
  <exec executable="phpcs">
    <arg line="--report=checkstyle 
 --report-file=${project.basedir}/build/logs/checkstyle.xml
 --standard=Zend
 ${project.basedir}/*.php" />
  </exec>
 </target>

And when i do it in command line, I have a different result. My command :

phpcs --report=checkstyle --report-file=checkstyle.xml --standard=Zend *.php

It generates the same checkstyle.xml with no errors, and a phpcs-checkstyle.tmp which contains the errors.

How can I do to have the results with the errors in my checkstyle.xml file ?

Thanks.


回答1:


I think your problem is that you are suffering from this bug: http://pear.php.net/bugs/bug.php?id=19930

The bug only occurs in the RC version you are using.

Reverting to the current stable version (1.4.5) should get things working again for you.




回答2:


I believe that the reason you're having issues when running the command in Jenkins (ant) is because of the wildcard asterisk you're using. The wildcard is expanded by the linux shell, but not by ant.

Try removing the wildcard.

<target name="phpcs" >
  <exec executable="phpcs">
    <arg line="--report=checkstyle 
      --report-file=${project.basedir}/build/logs/checkstyle.xml
      --standard=Zend
      ${project.basedir}" />
  </exec>
</target>

If you're concerned that phpcs will run against non-php files, you can pass an extensions parameter: http://pear.php.net/manual/en/package.php.php-codesniffer.advanced-usage.php

<target name="phpcs" >
  <exec executable="phpcs">
    <arg line="--report=checkstyle 
      --report-file=${project.basedir}/build/logs/checkstyle.xml
      --standard=Zend
      --extensions=php
      ${project.basedir}" />
  </exec>
</target>

Though, by default phpcs only checks .inc and .php files anyhow.



来源:https://stackoverflow.com/questions/16673963/using-jenkins-and-php-code-sniffer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!