我正在Jenkins工作中运行PMD。我的Shell脚本构建步骤如下。
alias pmd="/root/pmd-bin-6.11.0/bin/run.sh pmd"
pmd -d "/var/jenkins_home/workspace/Warnings" -R rulesets/java/quickstart.xml -f xml > results.xml
生成的result.xml文件非常好。但是,在我的控制台日志中,上面写着。
"Build step 'Execute shell' marked build as failure".
我是Bash / Linux / Shell脚本的新手,请帮帮我。谢谢。
控制台日志
15:04:11 Started by user admin
15:04:11 [EnvInject] - Loading node environment variables.
15:04:11 Building in workspace /var/jenkins_home/workspace/Warnings
15:04:11 [WS-CLEANUP] Deleting project workspace...
15:04:11 [WS-CLEANUP] Deferred wipeout is used...
15:04:11 [WS-CLEANUP] Done
15:04:11 using credential creds
15:04:11 Cloning the remote Git repository
15:04:11 Cloning repository https://github.com/at/coder
15:04:11 > git init /var/jenkins_home/workspace/Warnings # timeout=10
15:04:11 Fetching upstream changes from https://github.com/at/coder
15:04:11 > git --version # timeout=10
15:04:26 [Warnings] $ /bin/sh /tmp/jenkins5909715001648669215.sh
15:04:29 Feb 08, 2019 9:34:29 AM net.sourceforge.pmd.RuleSetFactory parseRuleReferenceNode
15:04:29 WARNING: Discontinue using Rule name category/java/multithreading.xml/UnsynchronizedStaticDateFormatter as it is scheduled for removal from PMD. PMD 7.0.0 will remove support for this Rule.
15:04:29 Feb 08, 2019 9:34:29 AM net.sourceforge.pmd.PMD processFiles
15:04:29 WARNING: This analysis could be faster, please consider using Incremental Analysis: https://pmd.github.io/pmd-6.11.0/pmd_userdocs_incremental_analysis.html
15:04:49 Build step 'Execute shell' marked build as failure
15:04:49 using credential creds
15:04:49 [PMD] Searching for all files in '/var/jenkins_home/workspace/Warnings' that match the pattern '**/results.xml'
15:04:49 [PMD] -> found 1 file
15:04:49 [PMD] Successfully parsed file /var/jenkins_home/workspace/Warnings/results.xml
15:04:49 [PMD] -> found 1967 issues (skipped 0 duplicates)
15:04:49 > git rev-parse e84e3873745f2413bd8e807847552011f5cb2c2c^{commit} # timeout=10
15:05:15 [PMD] Post processing issues on 'Master' with encoding 'UTF-8'
15:05:15 [PMD] Resolving absolute file names for all issues in workspace '/var/jenkins_home/workspace/Warnings'
15:05:15 [PMD] -> 0 resolved, 0 unresolved, 426 already resolved
15:05:15 [PMD] Copying affected files to Jenkins' build folder '/var/jenkins_home/jobs/Warnings/builds/42/files-with-issues'
15:05:15 [PMD] -> 426 copied, 0 not in workspace, 0 not-found, 0 with I/O error
15:05:15 [PMD] Resolving module names from module definitions (build.xml, pom.xml, or Manifest.mf files)
15:05:15 [PMD] -> resolved module names for 1967 issues
15:05:15 [PMD] Resolving package names (or namespaces) by parsing the affected files
15:05:15 [PMD] -> all affected files already have a valid package name
15:05:15 [PMD] No filter has been set, publishing all 1967 issues
15:05:15 [PMD] Creating fingerprints for all affected code blocks to track issues over different builds
15:05:15 [PMD] -> created fingerprints for 1967 issues
15:05:15 [PMD] Invoking Git blamer to create author and commit information for all affected files
15:05:15 [PMD] GIT_COMMIT env = 'e84e3873745f2413bd8e807847552011f5cb2c2c'
15:05:15 [PMD] Git working tree = '/var/jenkins_home/workspace/Warnings'
15:05:15 [PMD] Git commit ID = 'e84e3873745f2413bd8e807847552011f5cb2c2c'
15:05:15 [PMD] Job workspace = '/var/jenkins_home/workspace/Warnings'
15:05:15 [PMD] Created blame requests for 426 files - invoking Git blame on agent for each of the requests
15:05:15 [PMD] -> blamed authors of issues in 426 files
15:05:15 [Static Analysis] Attaching ResultAction with ID 'analysis' to run 'Warnings #42'.
15:05:15 [Static Analysis] Using reference build 'Warnings #41' to compute new, fixed, and outstanding issues
15:05:15 [Static Analysis] Issues delta (vs. reference build): outstanding: 1967, new: 0, fixed: 0
15:05:15 [Static Analysis] No quality gates have been set - skipping
15:05:15 [Static Analysis] Health report is disabled - skipping
15:05:16 [Static Analysis] Created analysis result for 1967 issues (found 0 new issues, fixed 0 issues)
15:05:16 Sending e-mails to: decker@devep.com
15:05:17 Finished: FAILURE
答案 0 :(得分:1)
如果在构建时发现任何违规,则PMD将返回非零代码。您可以禁用此功能,并在分析结束时获得出口0,这会将您的构建标记为成功。
请参见以下示例:
pmd -d "/var/jenkins_home/workspace/Warnings" -R rulesets/java/quickstart.xml -f xml -failOnViolation false> results.xml
有关更多信息,请查看this文档。
答案 1 :(得分:0)
Jenkins将每个返回状态!= 0解释为您的批处理命令失败。在大多数情况下,这非常令人遗憾。例如,如果您使用robocopy,成功复制文件将返回状态= 0-即使复制成功-因此Jenkins会将构建标记为失败。
您可以禁止状态码-或让批处理命令始终返回0-这样Jenkins会将您的构建标记为成功。后缀^& exit 0
将为您完成此任务。
bat <execute your command here> ^& exit 0