【问题标题】:Configuring Findbugs in Jenkins在 Jenkins 中配置 Findbugs
【发布时间】:2016-11-24 11:46:39
【问题描述】:

我的目标是让我的项目的 jenkins 构建失败,以防 FindBugs 插件报告错误。为此,我在项目的 pom.xml 中集成了 FindBugs 配置,配置的执行部分如下

               <executions>
                    <execution>
                        <id>analyze-compile</id>
                        <phase>compile</phase>
                        <goals><goal>check</goal></goals>
                        <configuration>
                            <threshold>High</threshold>
                        </configuration>
                    </execution>
                </executions>

我从在线资源中找到了上述配置,并且使用此配置,项目不会因 FindBugs 报告的错误而失败。我也尝试过其他配置,如下所示

<xmlOutput>true</xmlOutput>
<configuration>
    <failOnError>${findbugs.failOnError}</failOnError>
    <threshold>High</threshold>
    </configuration>
<executions>
    <execution>
        <id>noFailOnError</id>
            <phase>verify</phase>
        <goals>
            <goal>check</goal>
        </goals>
            <configuration>                                        
               <failOnError>false</failOnError>
        </configuration>
    </execution>
    <execution>
        <id>failOnError</id>
        <phase>install</phase>
        <goals>
            <goal>check</goal>
        </goals>
            <configuration>
                <failOnError>true</failOnError>
            </configuration>
     </execution>
</executions>

有人可以告诉我在 FindBugs 中出现错误的情况下需要用于失败构建的正确执行是什么?

【问题讨论】:

    标签: maven jenkins pom.xml findbugs


    【解决方案1】:

    以下是 pom.xml 中 find-bugs 的正确配置。它执行以下操作 - 执行 FindBugs 检查,在验证阶段生成 xml 报告,将其转换为 html 并在检查期间出现错误时构建失败

    <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>findbugs-maven-plugin</artifactId>
                    <version>2.4.0</version>
                    <executions>
                        <execution>
                            <id>findbug</id>
                            <phase>verify</phase>
                            <goals>
                                <goal>check</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <effort>Max</effort>
                        <threshold>Low</threshold>
                        <findbugsXmlOutputDirectory>
                            ${project.build.directory}/findbugs
                        </findbugsXmlOutputDirectory>
                        <failOnError>false</failOnError>
                    </configuration>
                </plugin>
    
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>xml-maven-plugin</artifactId>
                    <version>1.0</version>
                    <executions>
                        <execution>
                            <phase>verify</phase>
                            <goals>
                                <goal>transform</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <transformationSets>
                            <transformationSet>
                                <dir>${project.build.directory}/findbugs</dir>
                                <outputDir>${project.build.directory}/findbugs</outputDir>
                                <stylesheet>fancy-hist.xsl</stylesheet>
                                <!--<stylesheet>default.xsl</stylesheet> -->
                                <!--<stylesheet>plain.xsl</stylesheet> -->
                                <!--<stylesheet>fancy.xsl</stylesheet> -->
                                <!--<stylesheet>summary.xsl</stylesheet> -->
                                <fileMappers>
                                    <fileMapper
                                        implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
                                        <targetExtension>.html</targetExtension>
                                    </fileMapper>
                                </fileMappers>
                            </transformationSet>
                        </transformationSets>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>com.google.code.findbugs</groupId>
                            <artifactId>findbugs</artifactId>
                            <version>2.0.0</version>
                        </dependency>
                    </dependencies>
                </plugin>
    
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>findbugs-maven-plugin</artifactId>
                    <version>3.0.3</version>
                    <executions>
                        <execution>
                            <id>failing-on-high</id>
                            <phase>install</phase>
                            <goals>
                                <goal>findbugs</goal>
                                <goal>check</goal>
                            </goals>
                            <configuration>
                                <effort>Max</effort>
                                <threshold>Low</threshold>
                                <failOnError>true</failOnError>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-30
      • 2014-01-19
      • 1970-01-01
      相关资源
      最近更新 更多