如何在詹金斯管道上发布 cppcheck 结果?

how to publish cppcheck results on jenkins pipeline?

我正在自学 Jenkins,我想尝试 cppcheck 插件,我设置了以下示例管道:

pipeline {
    agent any

    stages {
        stage('analysis') {
            steps {
                script{
                    bat'cppcheck "E:/Source" --force — enable=all — inconclusive — xml — xml-version=2 . 2 > cppcheck.xml'
                }
            }
        }
    }
    post {
        always {
            // scanForIssues tool: cppCheck(pattern: 'cppcheck.xml')
            publishCppcheck pattern:'cppcheck.xml'
        }
    }
}

但是我在 post 步骤中遇到错误,我不知道它是否与我的项目有关,或者我做错了什么。我已按照此线程 上的说明进行操作,但它似乎不起作用,我是否使用 publushCppcheck :

[Pipeline] { (Declarative: Post Actions)
[Pipeline] publishCppcheck (hide)
[Cppcheck] Starting the cppcheck analysis.
[Cppcheck] Processing 1 files with the pattern 'cppcheck.xml'.
[Cppcheck] Parsing throws exceptions. javax.xml.bind.UnmarshalException
 - with linked exception:
[org.xml.sax.SAXParseException; systemId: file:/C:/Users/anton/.jenkins/workspace/JOB4/cppcheck.xml; lineNumber: 1; columnNumber: 1; El contenido no está permitido en el prólogo.]
[Cppcheck] java.io.IOException: javax.xml.bind.UnmarshalException
 - with linked exception:
[org.xml.sax.SAXParseException; systemId: file:/C:/Users/anton/.jenkins/workspace/JOB4/cppcheck.xml; lineNumber: 1; columnNumber: 1; El contenido no está permitido en el prólogo.]
    at org.jenkinsci.plugins.cppcheck.parser.CppcheckParser.parse(CppcheckParser.java:67)
    at org.jenkinsci.plugins.cppcheck.CppcheckParserResult.invoke(CppcheckParserResult.java:69)
    at org.jenkinsci.plugins.cppcheck.CppcheckParserResult.invoke(CppcheckParserResult.java:24)
    at hudson.FilePath.act(FilePath.java:1164)
    at hudson.FilePath.act(FilePath.java:1147)
    at org.jenkinsci.plugins.cppcheck.CppcheckPublisher.perform(CppcheckPublisher.java:337)
    at jenkins.tasks.SimpleBuildStep.perform(SimpleBuildStep.java:123)
    at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:99)
    at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:69)
    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start[=11=](SynchronousNonBlockingStepExecution.java:47)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: javax.xml.bind.UnmarshalException

scanforIssues 来自警告 ng 插件::

[Pipeline] { (Declarative: Post Actions)
[Pipeline] scanForIssues
[CPPCheck] [-ERROR-] Parsing of file 'C:\Users\anton\.jenkins\workspace\JOB4@2\cppcheck.xml' failed due to an exception:
[CPPCheck] [-ERROR-] com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character 'C' (code 67) in prolog; expected '<'
 at [row,col {unknown-source}]: [1,1]
[CPPCheck] [-ERROR-]  at [row,col {unknown-source}]: [1,1]
[CPPCheck] [-ERROR-]    at com.ctc.wstx.sr.StreamScanner.throwUnexpectedChar(StreamScanner.java:648)
[CPPCheck] [-ERROR-]    at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2047)
[CPPCheck] [-ERROR-]    at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1069)
[CPPCheck] [-ERROR-]    at se.bjurr.violations.lib.parsers.CPPCheckParser.parseReportOutput(CPPCheckParser.java:43)
[CPPCheck] [-ERROR-]    at edu.hm.hafner.analysis.parser.violations.AbstractViolationAdapter.parse(AbstractViolationAdapter.java:35)
[CPPCheck] [-ERROR-]    at io.jenkins.plugins.analysis.core.model.FilesScanner.aggregateIssuesOfFile(FilesScanner.java:105)
[CPPCheck] [-ERROR-]    at io.jenkins.plugins.analysis.core.model.FilesScanner.scanFiles(FilesScanner.java:89)
[CPPCheck] [-ERROR-]    at io.jenkins.plugins.analysis.core.model.FilesScanner.invoke(FilesScanner.java:72)
[CPPCheck] [-ERROR-]    at io.jenkins.plugins.analysis.core.model.FilesScanner.invoke(FilesScanner.java:30)
[CPPCheck] [-ERROR-]    at hudson.FilePath.act(FilePath.java:1164)
[CPPCheck] [-ERROR-]    at hudson.FilePath.act(FilePath.java:1147)
[CPPCheck] [-ERROR-]    at io.jenkins.plugins.analysis.core.model.ReportScanningTool.scanInWorkspace(ReportScanningTool.java:152)
[CPPCheck] [-ERROR-]    at io.jenkins.plugins.analysis.core.model.ReportScanningTool.scan(ReportScanningTool.java:134)
[CPPCheck] [-ERROR-]    at io.jenkins.plugins.analysis.core.steps.IssuesScanner.scan(IssuesScanner.java:95)
[CPPCheck] [-ERROR-]    at io.jenkins.plugins.analysis.core.steps.ScanForIssuesStep$Execution.run(ScanForIssuesStep.java:214)
[CPPCheck] [-ERROR-]    at io.jenkins.plugins.analysis.core.steps.ScanForIssuesStep$Execution.run(ScanForIssuesStep.java:175)
[CPPCheck] [-ERROR-]    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start[=12=](SynchronousNonBlockingStepExecution.java:47)
[CPPCheck] [-ERROR-]    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
[CPPCheck] [-ERROR-]    at java.util.concurrent.FutureTask.run(Unknown Source)
[CPPCheck] [-ERROR-]    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
[CPPCheck] [-ERROR-]    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
[CPPCheck] [-ERROR-]    at java.lang.Thread.run(Unknown Source)
[CPPCheck] [-ERROR-]  [wrapped] edu.hm.hafner.analysis.ParsingException: Exception occurred during parsing
WstxUnexpectedCharException: Unexpected character 'C' (code 67) in prolog; expected '<'
 at [row,col {unknown-source}]: [1,1]
com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character 'C' (code 67) in prolog; expected '<'
 at [row,col {unknown-source}]: [1,1]
    at com.ctc.wstx.sr.StreamScanner.throwUnexpectedChar(StreamScanner.java:648)
    at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2047)
    at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1069)
    at se.bjurr.violations.lib.parsers.CPPCheckParser.parseReportOutput(CPPCheckParser.java:43)
    at edu.hm.hafner.analysis.parser.violations.AbstractViolationAdapter.parse(AbstractViolationAdapter.java:35)
    at io.jenkins.plugins.analysis.core.model.FilesScanner.aggregateIssuesOfFile(FilesScanner.java:105)
    at io.jenkins.plugins.analysis.core.model.FilesScanner.scanFiles(FilesScanner.java:89)
    at io.jenkins.plugins.analysis.core.model.FilesScanner.invoke(FilesScanner.java:72)
    at io.jenkins.plugins.analysis.core.model.FilesScanner.invoke(FilesScanner.java:30)
    at hudson.FilePath.act(FilePath.java:1164)
    at hudson.FilePath.act(FilePath.java:1147)
    at io.jenkins.plugins.analysis.core.model.ReportScanningTool.scanInWorkspace(ReportScanningTool.java:152)
    at io.jenkins.plugins.analysis.core.model.ReportScanningTool.scan(ReportScanningTool.java:134)
    at io.jenkins.plugins.analysis.core.steps.IssuesScanner.scan(IssuesScanner.java:95)
    at io.jenkins.plugins.analysis.core.steps.ScanForIssuesStep$Execution.run(ScanForIssuesStep.java:214)
    at io.jenkins.plugins.analysis.core.steps.ScanForIssuesStep$Execution.run(ScanForIssuesStep.java:175)
    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start[=12=](SynchronousNonBlockingStepExecution.java:47)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

到目前为止我还不是这方面的专家,但我认为您可能想尝试一下:
publishCppcheck(pattern: 'cppcheck.xml')