Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-48475

Build step returns null if propagate set to true

      When running a build from another job and setting the propagate property to true, if the downstream job fails, the returned value is null.

      For example, if I want to copy the artifacts and I use returnValue.getNumber(), I get the error message:
      java.lang.NullPointerException: Cannot invoke method getNumber() on null object

          [JENKINS-48475] Build step returns null if propagate set to true

          Gil Shinar created issue -

          Andrew Bayer added a comment -

          This is correct/expected behavior - check the help text for propagate at https://jenkins.io/doc/pipeline/steps/pipeline-build-step/#build-build-a-job. If propagate is true and the downstream build fails/is aborted/is unstable, the build step fails and returns null. If you want to act on the result of the downstream build, you want propagate set to false.

          Andrew Bayer added a comment - This is correct/expected behavior - check the help text for propagate at https://jenkins.io/doc/pipeline/steps/pipeline-build-step/#build-build-a-job . If propagate is true and the downstream build fails/is aborted/is unstable, the build step fails and returns null. If you want to act on the result of the downstream build, you want propagate set to false.
          Andrew Bayer made changes -
          Resolution New: Not A Defect [ 7 ]
          Status Original: Open [ 1 ] New: Resolved [ 5 ]

          vadim sluzky added a comment -

          I can not agree that this is a correct behavior. It's a blocker for the following use case I'm trying to implement:

          • Run a set of tests represented by Jenkins Jobs
          • For jobs that fail post name of the test and a link to a corresponding build

          For failing tests build step returns null and I can't get BUILD_URL

          May you suggest an alternative way to unblock me?

          vadim sluzky added a comment - I can not agree that this is a correct behavior. It's a blocker for the following use case I'm trying to implement: Run a set of tests represented by Jenkins Jobs For jobs that fail post name of the test and a link to a corresponding build For failing tests build step returns null and I can't get BUILD_URL May you suggest an alternative way to unblock me?

          Andrew Bayer added a comment -

          Set `propagate` to false.

          Andrew Bayer added a comment - Set `propagate` to false.

          vadim sluzky added a comment -

          Got it. I set propagate to false and then analyzed result field. Thank you for quick help, Andrew!

          vadim sluzky added a comment - Got it. I set propagate to false and then analyzed result field. Thank you for quick help, Andrew!

          vadim sluzky added a comment - - edited

          There is still a problem with that implementation.

          If propagate is set to false, all the corresponding tests are displayed in GREEN

          Is it possible to let the upstream  job know about failures?

          Are there any problems with returning real non-null result if wait is true?

           What is the logic behind using 'propagate' field to whether returning result?

          I strongly believe it should be returned or not based on 'wait' parameter and this is a valid non-minor defect that does not have a workaround and needs to be fixed

           

          vadim sluzky added a comment - - edited There is still a problem with that implementation. If propagate is set to false, all the corresponding tests are displayed in GREEN Is it possible to let the upstream  job know about failures? Are there any problems with returning real non-null result if wait is true?  What is the logic behind using 'propagate' field to whether returning result? I strongly believe it should be returned or not based on 'wait' parameter and this is a valid non-minor defect that does not have a workaround and needs to be fixed  

          vadim sluzky added a comment -

          I can not agree with resolution "Resolved" because it is "not a defect".

          If a build is not SUCCESSFUL, there is a need to have it results like a link to BUILD_URL.

          Consider the following use case:

              Run Tests as Jenkins jobs called from pipeline

              Provide links to jobs that failed

          The suggested solution is to set propagate to false that results in displaying all builds/tests as SUCCESSFUL - it's not acceptable.

          IMO, whether or not to return results of execution should depend on wait parameter. If wait is true, results should be available and should be returned. If wait is false - build is only launched without waiting to its completion - then result is not available.

          That should not be related to 'propagate' 

          vadim sluzky added a comment - I can not agree with resolution "Resolved" because it is "not a defect". If a build is not SUCCESSFUL, there is a need to have it results like a link to BUILD_URL. Consider the following use case:     Run Tests as Jenkins jobs called from pipeline     Provide links to jobs that failed The suggested solution is to set propagate to false that results in displaying all builds/tests as SUCCESSFUL - it's not acceptable. IMO, whether or not to return results of execution should depend on wait parameter. If wait is true, results should be available and should be returned. If wait is false - build is only launched without waiting to its completion - then result is not available. That should not be related to 'propagate' 
          vadim sluzky made changes -
          Resolution Original: Not A Defect [ 7 ]
          Status Original: Resolved [ 5 ] New: Reopened [ 4 ]

          Andrew Bayer added a comment -

          So this is definitely a confusing setting, no question. The problem here is that propagate really just means "if the downstream build fails, this step fails too". That directly results in returning null - a failed Pipeline step can't return anything. I'll leave this open in case an alternative approach comes to mind, but I don't think there's a way to achieve what you want.

          Andrew Bayer added a comment - So this is definitely a confusing setting, no question. The problem here is that propagate really just means "if the downstream build fails, this step fails too". That directly results in returning null - a failed Pipeline step can't return anything. I'll leave this open in case an alternative approach comes to mind, but I don't think there's a way to achieve what you want.

            Unassigned Unassigned
            gils Gil Shinar
            Votes:
            3 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated: