3

I have a pipeline in Jenkins whose first stage is about triggering another job with the build function. I want to have the RunWrapper object back from the build function, but it returns a null object when the wait paramater is set to false.

Basically, in this case the build function returns the correct object type :

stage('Trigger Another Job With Propagate') {
   steps {
      script {
         triggeredJob = build(job: 'Tiggered_Job', wait: true)

         echo "${triggeredJob.getClass()}"
         // correct object type
      }
   }
}

But when we don't want to wait the job to finish before stepping into the next stages, a null object is returned :

stage('Trigger Another Job With Propagate') {
   steps {
      script {
         triggeredJob = build(job: 'Tiggered_Job', wait: false)

         echo "${triggeredJob.getClass()}"
         // null object type
      }
   }
}

I think that behavior is not normal, we should be able to use the object in any case.

STerliakov
  • 4,983
  • 3
  • 15
  • 37
  • Why do you want to access the Job if you are not waiting? – ycr Aug 10 '22 at 11:26
  • 1
    Because I want to parent Job to continue next stages while the child Job is also running. I can't use parallel { } because the child Job already has stages executing in parallel, and Jenkins doesn't know how to execute parallel of parallel tasks as far as I know – Karim Lechguy Aug 11 '22 at 14:58
  • 1
    Same situation here. In my naive phantasies I had expected to get something like a "promise" that would be filled with job info as and when it became available. But `null` is really a hefty disillusionment ;) – MBaas Nov 30 '22 at 13:00

0 Answers0