【发布时间】:2017-12-06 09:30:36
【问题描述】:
我正在通过 pom.xml 中的 maven 插件运行 pmd(以及 checkstyle 和 findbugs)。由于 pmd 报告的错误,Jenkins 上的构建失败。
构建阶段并行运行 6 个模块,然后我运行发布者和另一个阶段。如果 pmd 失败,整个构建将失败并立即停止。
这是来自我的 pom.xml 的 sn-p:
</properties>
<failOnChecks>true</failOnChecks>
</properties>
<!-- ...... -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.8</version>
<dependencies>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-core</artifactId>
<version>${version.pmd}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-java</artifactId>
<version>${version.pmd}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-javascript</artifactId>
<version>${version.pmd}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.pmd</groupId>
<artifactId>pmd-jsp</artifactId>
<version>${version.pmd}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>my.software</groupId>
<artifactId>build-tools</artifactId>
<version>${version.build-tools}</version>
</dependency>
</dependencies>
<configuration>
<rulesets>
<ruleset>pmd/ruleset.xml</ruleset>
</rulesets>
<failOnViolation>${failOnChecks}</failOnViolation>
</configuration>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
Jenkinsfile 有这两个阶段:
stage('modules') {
gitlabCommitStatus('modules') {
parallel Config.stepsForParallel
}
}
stage('Jenkins Code Analysis') {
pmd canRunOnFailed: true, canComputeNew: false, defaultEncoding: '', healthy: '', pattern: '', unHealthy: ''
checkstyle canRunOnFailed: true, canComputeNew: false, defaultEncoding: '', healthy: '', pattern: '', unHealthy: ''
//findbugs canComputeNew: false, defaultEncoding: '', excludePattern: '', healthy: '', includePattern: '', pattern: '', unHealthy: ''
}
在到达第二阶段之前构建失败。
插件不应该停止管道,而是完成它然后失败,然后运行发布者,所以我可以在 Jenkins 中看到问题。
到目前为止,我通过属性设置了 failOnViolation,但我无法让构建最终失败。我想我需要在某处检查状态并调用错误。
有没有更简洁的方法来实现这一点?
【问题讨论】:
-
首先为什么要定义插件的依赖关系?此外,您是否检查过通过以下方式致电 Maven:
mvn --fail-at-end ...? -
1:这是由一位同事完成的。我想他这样做是有他的理由的。我可能可以删除它们。 2:--fail-at-end 可能不起作用,因为每个构建都运行自己的 mvn 命令。 --fail-never 可能也不是那么好,因为它也可能抑制任何其他失败。
-
将这些依赖项添加到插件中并没有真正意义,因为插件已经具有这些依赖项......您是否使用 CI 解决方案来运行这些构建?如果是,您可以更改 Maven 调用的配置。
-
-fae不会停止管道。如果您构建有问题,则管道将停止。如果在这种情况下需要继续,则需要在管道中缓存错误... -
当您想要运行最新版本的 PMD 时,这些依赖项才有意义。 maven-pmd-plugin 通常落后于几个 PMD 版本,因为它的更新频率低于 PMD 本身。截至目前,maven-pmd-plugin 使用 PMD 5.6.1,而 PMD 的最新版本是 5.8.1。