简体   繁体   English

使用Jenkins和Php Code Sniffer

[英]Using Jenkins and Php Code Sniffer

I'm trying to use the Php Code Sniffer plugin in Jenkins. 我正在尝试在Jenkins中使用Php Code Sniffer插件。 It generates a checkstyle.xml file but there are no errors inside, and I know that I should have. 它生成一个checkstyle.xml文件,但里面没有错误,我知道我应该有。

Here's the containt of my checkstyle.xml : 这是我的checkstyle.xml的内容:

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

My build.xml file for Jenkins is : 我的Jenkins的build.xml文件是:

<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. 它生成相同的checkstyle.xml而没有错误,以及包含错误的phpcs-checkstyle.tmp。

How can I do to have the results with the errors in my checkstyle.xml file ? 如何使用checkstyle.xml文件中的错误获得结果?

Thanks. 谢谢。

I think your problem is that you are suffering from this bug: http://pear.php.net/bugs/bug.php?id=19930 我认为你的问题是你正在遭受这个错误: http//pear.php.net/bugs/bug.php?id = 199130

The bug only occurs in the RC version you are using. 该错误仅发生在您正在使用的RC版本中。

Reverting to the current stable version (1.4.5) should get things working again for you. 恢复到当前的稳定版本(1.4.5)应该可以让你再次工作。

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. 我相信你在Jenkins(ant)中运行命令时遇到问题的原因是因为你正在使用通配符星号。 The wildcard is expanded by the linux shell, but not by ant. 通配符由linux shell扩展,但不是由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 如果你担心phpcs会针对非php文件运行,你可以传递一个扩展参数: 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. 虽然,默认情况下phpcs只检查.inc和.php文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM