在 Jenkins 中配置 Findbugs

Configuring Findbugs in Jenkins

我的目标是让我的项目的 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 中出现错误时构建失败需要使用的正确执行是什么吗?

以下是 pom.xml 中查找错误的正确配置。它执行以下操作 - 执行 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>