带有SonarQubeEnv的Jenkinsfile已完成:成功执行步骤后失败

时间:2019-02-18 14:49:24

标签: jenkins-pipeline sonarqube-scan

我们有一个詹金斯管道作业,在所有阶段成功执行后失败。

管道称为sonartest,它从git获取一个jenkinsfile sonar.jenkins。

示例脚本是将我们真正的jenkinsfile剥离到导致问题的部分的结果。在真正的jenkins文件中,withSonarQubeEnv内部并行执行了几个声纳扫描。扫描本身全部成功,在示例中,我用一个简单的dir语句替换了它们。

如果我删除withSonarQubeEnv,管道不会出错。

样本

def nodelabel = "windows"
def applroot = "C:\\temp\\"

node(nodelabel) {
        stage('SonarQube training analysis') {
            withSonarQubeEnv('SonarQube') {

                dir("${applroot}") {
                      bat "dir"
                }

            }
        }
}

控制台输出

Started by user 
Obtained buildfiles/sonar.jenkins from git ssh://git:7999/gitest/jenkinsbuildtest.git
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on hostname in C:\workspaces\jenkins\workspace\sonartest
[Pipeline] {
[Pipeline] stage
[Pipeline] { (SonarQube training analysis)
[Pipeline] withSonarQubeEnv
Injecting SonarQube environment variables using the configuration: SonarQube
[Pipeline] {
[Pipeline] dir
Running in C:\temp
[Pipeline] {
[Pipeline] bat

C:\temp>dir
 Volume in drive C has no label.
 Volume Serial Number is 9E5D-D8F8

 Directory of C:\temp

18/02/2019  15:00    <DIR>          .
18/02/2019  15:00    <DIR>          ..

// trimmed

            8061 File(s)     80ÿ494ÿ243 bytes
              21 Dir(s)  130ÿ154ÿ577ÿ920 bytes free
[Pipeline] }
[Pipeline] // dir
[Pipeline] }
[Pipeline] // withSonarQubeEnv
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Also:   hudson.remoting.Channel$CallSiteStackTrace: Remote call to JNLP4-connect connection from hostname/XXX.XXX.XXX.31:61231
        at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1743)
        at hudson.remoting.UserResponse.retrieve(UserRequest.java:389)
        at hudson.remoting.Channel.call(Channel.java:957)
        at hudson.FilePath.act(FilePath.java:1068)
        at hudson.FilePath.act(FilePath.java:1057)
        at hudson.FilePath.list(FilePath.java:1891)
        at hudson.FilePath.list(FilePath.java:1875)
        at hudson.FilePath.list(FilePath.java:1860)
        at hudson.plugins.sonar.utils.SonarUtils.extractReportTask(SonarUtils.java:84)
        at hudson.plugins.sonar.utils.SonarUtils.addBuildInfoTo(SonarUtils.java:111)
        at hudson.plugins.sonar.SonarBuildWrapper$AddBuildInfo.tearDown(SonarBuildWrapper.java:170)
        at org.jenkinsci.plugins.workflow.steps.CoreWrapperStep$Callback.finished(CoreWrapperStep.java:152)
        at org.jenkinsci.plugins.workflow.steps.CoreWrapperStep$Execution2$Callback2.finished(CoreWrapperStep.java:122)
        at org.jenkinsci.plugins.workflow.steps.GeneralNonBlockingStepExecution$TailCall.lambda$onSuccess$0(GeneralNonBlockingStepExecution.java:140)
        at org.jenkinsci.plugins.workflow.steps.GeneralNonBlockingStepExecution.lambda$run$0(GeneralNonBlockingStepExecution.java:77)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
java.io.IOException: C:\workspaces\jenkins\workspace\sonartest does not exist.
    at hudson.FilePath.glob(FilePath.java:1931)
    at hudson.FilePath.access$3200(FilePath.java:209)
    at hudson.FilePath$ListGlob.invoke(FilePath.java:1905)
    at hudson.FilePath$ListGlob.invoke(FilePath.java:1893)
    at hudson.FilePath$FileCallableWrapper.call(FilePath.java:3041)
    at hudson.remoting.UserRequest.perform(UserRequest.java:210)
    at hudson.remoting.UserRequest.perform(UserRequest.java:53)
    at hudson.remoting.Request$2.run(Request.java:358)
    at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
    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 hudson.remoting.Engine$1$1.run(Engine.java:94)
    at java.lang.Thread.run(Unknown Source)
Finished: FAILURE

1 个答案:

答案 0 :(得分:0)

我找到了解决此问题的方法。 当我将withSonarQubeEnv放在dir("${applroot}") {}中时。 在简化的示例中,不再需要内部目录,在我的真实世界脚本中,不同目录中存在多个不同的并行执行的声纳扫描。

解决

def nodelabel = "windows"
def applroot = "C:\\temp\\"

node(nodelabel) {
    stage('SonarQube training analysis') {
        dir("${applroot}") {
            withSonarQubeEnv('SonarQube') {
                dir("${applroot}") {
                     bat "dir"
                }
            }
        }
    }
}