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

build.state.result always SUCCESS in guard block

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Won't Fix
    • Component/s: build-flow-plugin
    • Labels:
      None
    • Environment:
      Jenkins 1.639
    • Similar Issues:

      Description

      build.state.result should return FAILURE in the guard block, but always returns SUCCESS.

      Script

      import hudson.model.Result
      
      def run_builds(){
          parallel (
          {
              ignore(FAILURE) {build("Tests/TestSuccess")}
              build("Tests/TestSuccess")
          },
          {
              build("Tests/TestSuccess")
              build("Tests/TestFailure")
          },
      )}
      
      guard {
          run_builds()
      } rescue {
          out.println "Result should be FAILURE but is $build.state.result"
      }
      

      Output console

      guard {
          parallel {
              Schedule job Jenkins internal tests » TestSuccess
              ignore(FAILURE) {
                  Schedule job Jenkins internal tests » TestSuccess
                  Build Jenkins internal tests » TestSuccess #20 started
                  Build Jenkins internal tests » TestSuccess #20 started
                  Jenkins internal tests » TestSuccess #20 completed 
                  Jenkins internal tests » TestSuccess #20 completed 
                  // SUCCESS ignored
              }
              Schedule job Jenkins internal tests » TestFailure
              Schedule job Jenkins internal tests » TestSuccess
              Build Jenkins internal tests » TestFailure #12 started
              Build Jenkins internal tests » TestSuccess #21 started
              Jenkins internal tests » TestFailure #12 completed  : FAILURE
              Jenkins internal tests » TestSuccess #21 completed 
          }
      } rescue {
      Result should be FAILURE but is SUCCESS
      }
      

        Attachments

          Activity

          Hide
          martin_stolle Martin Stolle added a comment -

          Or even shorter:

          Code

          guard {
              build("Tests/TestFailure")
          } rescue {
              out.println "Result should be FAILURE but is $build.state.result"
          }
          

          Console

          guard {
              Schedule job Jenkins internal tests » TestFailure
              Build Jenkins internal tests » TestFailure #17 started
              Jenkins internal tests » TestFailure #17 completed  : FAILURE
          } rescue {
          Result should be FAILURE but is SUCCESS
          }
          
          Show
          martin_stolle Martin Stolle added a comment - Or even shorter: Code guard { build( "Tests/TestFailure" ) } rescue { out.println "Result should be FAILURE but is $build.state.result" } Console guard { Schedule job Jenkins internal tests » TestFailure Build Jenkins internal tests » TestFailure #17 started Jenkins internal tests » TestFailure #17 completed : FAILURE } rescue { Result should be FAILURE but is SUCCESS }
          Hide
          hofan41 Ho-Fan Kang added a comment -

          Having run time access to the global build state would allow for branching logic or status update logic. I personally would find this extremely useful.

          Show
          hofan41 Ho-Fan Kang added a comment - Having run time access to the global build state would allow for branching logic or status update logic. I personally would find this extremely useful.
          Hide
          martin_stolle Martin Stolle added a comment -

          Workflow Plugin is deprecated

          Show
          martin_stolle Martin Stolle added a comment - Workflow Plugin is deprecated

            People

            • Assignee:
              Unassigned
              Reporter:
              martin_stolle Martin Stolle
            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: