1
votes

I am trying to fetch Jenkins job result using the following code:

pipeline {
   agent { label 'Agent_Name' }


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

However, it looks like if I add "def res=" then the job fails with the following error:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:

If I remove def res=, then it works fine. Also, if I keep only def res=buid..... line in pipeline script, then it works fine too.

How can I fix this error? I need to get the result from the App_Build job and run the pipeline in stages.

1

1 Answers

1
votes

If you want to capture the result of the build step, you need to put it into script block, e.g.

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...
            }
         }
      }
   }
}