Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么执行Shell脚本的Jenkins构建步骤将构建标记为失败?_Shell_Jenkins_Pmd - Fatal编程技术网

为什么执行Shell脚本的Jenkins构建步骤将构建标记为失败?

为什么执行Shell脚本的Jenkins构建步骤将构建标记为失败?,shell,jenkins,pmd,Shell,Jenkins,Pmd,我在詹金斯的工作中运行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 生成的results.xml文件非常好。但是,在我的控制台日志中,它说 "Build step 'Execute shell' mark

我在詹金斯的工作中运行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
生成的results.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

如果在生成时发现任何冲突,PMD将返回非零代码。您可以禁用此功能,并在分析结束时获得出口0,该出口将标记您的构建成功

请参见以下示例:

pmd -d "/var/jenkins_home/workspace/Warnings" -R rulesets/java/quickstart.xml -f xml -failOnViolation false> results.xml

有关更多信息,请查看文档。

詹金斯解释每个退货状态!=0表示批处理命令失败。在大多数情况下,这是一个很好的注解。例如,如果使用robocopy,成功复制文件将返回状态!=0-即使复制成功-因此Jenkins将生成标记为失败

您可以取消状态代码,或者让batch命令始终返回0,这样Jenkins会将您的构建标记为成功。post fix^&退出0将为您执行此操作

bat <execute your command here> ^& exit 0

你查过詹金斯的控制台日志了吗?它可以提示失败的原因。嗨@nos,我已经添加了控制台日志。