Jenkins管道脚本错误-MultipleCompilationErrorsException

时间:2020-02-19 16:09:54

标签: jenkins groovy jenkins-pipeline

我正在尝试使用以下代码获取Jenkins的工作结果:

pipeline {
   agent { label 'Agent_Name' }


   stages {
      stage('Build') {
         steps {
            def res=build job: 'App_Build', parameters: [string(name: 'App', value: 'WindowsApp')]
         }
      }
   }
}

但是,如果我添加“ def res =“,则作业失败,并出现以下错误:

org.codehaus.groovy.control.MultipleCompilationErrorsException: 启动失败:

如果我删除def res=,则可以正常工作。另外,如果我在管道脚本中仅保留def res=buid.....行,那么它也可以正常工作。

如何解决此错误?我需要从App_Build作业中获取结果并分阶段运行管道。

1 个答案:

答案 0 :(得分:1)

如果要捕获build步骤的结果,则需要将其放入script块中,例如

pipeline {
   agent { label 'Agent_Name' }

   stages {
      stage('Build') {
         steps {
            script {
                def res=build job: 'App_Build', parameters: [string(name: 'App', value: 'WindowsApp')]
                // do something with the result...
            }
         }
      }
   }
}