Uploaded image for project: 'Jenkins Website'
  1. Jenkins Website
  2. WEBSITE-364

Update "currentBuild.result" docs and examples to use currentBuilt.currentResult and resultIsBetter/IsWorse

    Details

    • Type: Task
    • Status: To Do (View Workflow)
    • Priority: Minor
    • Resolution: Unresolved
    • Component/s: content
    • Labels:
      None
    • Similar Issues:

      Description

      Most of the time when people use currentBuild.result, they really want the behavior from currentBuild.currentResult or currentbuild.resultIsBettterOrEqualTo/currentbuild.resultIsWorseOrEqualTo (see linked issues).

      Review the existing documentation and update to use these new methods.

        Attachments

          Issue Links

            Activity

            Hide
            anthonymastrean Anthony Mastrean added a comment -

            I'm struggling to understand the difference (except that result is writable and possibly or often null, which may actually mean SUCCESS). Could you summarize?

            Show
            anthonymastrean Anthony Mastrean added a comment - I'm struggling to understand the difference (except that result is writable and possibly or often null , which may actually mean SUCCESS ). Could you summarize?
            Hide
            bitwiseman Liam Newman added a comment -

            Exactly, one is possibly (and often) null, the other is never null. So, for one users have to use currentBuild.result == null || currentBuild.result == 'SUCCESS', the other can always be checked as currentBuild.result == 'SUCCESS'. Even better, the behavior that most users probably want is currentbuild.resultIsBettterOrEqualTo('SUCCESS') and we should suggest they use that.

            Show
            bitwiseman Liam Newman added a comment - Exactly, one is possibly (and often) null, the other is never null. So, for one users have to use currentBuild.result == null || currentBuild.result == 'SUCCESS' , the other can always be checked as currentBuild.result == 'SUCCESS' . Even better, the behavior that most users probably want is currentbuild.resultIsBettterOrEqualTo('SUCCESS') and we should suggest they use that.
            Hide
            anthonymastrean Anthony Mastrean added a comment - - edited

            OK, it's good to know that I'm starting to understand! Could you possibly comment on the reliability of reading currentResult for use in various plugin steps (JENKINS-46325)?

            Show
            anthonymastrean Anthony Mastrean added a comment - - edited OK, it's good to know that I'm starting to understand! Could you possibly comment on the reliability of reading currentResult for use in various plugin steps ( JENKINS-46325 )?
            Hide
            bitwiseman Liam Newman added a comment -

            currentResult is reliable in the sense that it doesn't return null. However, it is still based on result. I've updated the referenced JIRA with additional details.

            As of Pipeline: Model Definition 1.1.9, when I run the following Pipeline:

            pipeline {
                agent any
                stages {
                    stage ('Init') {
                        steps {
                            echo "Init result: ${currentBuild.result}"
                            echo "Init currentResult: ${currentBuild.currentResult}"
                        }
                        post {
                            always {
                                echo "Post-Init result: ${currentBuild.result}"
                                echo "Post-Init currentResult: ${currentBuild.currentResult}"
                            }
                        }
                    }
                    stage ('Build') {
                        steps {
                            echo "During Build result: ${currentBuild.result}"
                            echo "During Build currentResult: ${currentBuild.currentResult}"
                            sh 'exit 1'
                        }
                        post {
                            always {
                                echo "Post-Build result: ${currentBuild.result}"
                                echo "Post-Build currentResult: ${currentBuild.currentResult}"
                            }
                        }
                    }
                }
                post {
                    always {
                        echo "Pipeline result: ${currentBuild.result}"
                        echo "Pipeline currentResult: ${currentBuild.currentResult}"
                    }
                }
            }
            

            I get this output (trimmed for clarity):

            Init result: null
            Init currentResult: SUCCESS
            Post-Init result: null
            Post-Init currentResult: SUCCESS
            During Build result: null
            During Build currentResult: SUCCESS
            [test-pipeline] Running shell script
            + exit 1
            Post-Build result: FAILURE
            Post-Build currentResult: FAILURE
            Pipeline result: FAILURE
            Pipeline currentResult: FAILURE
            ERROR: script returned exit code 1
            Finished: FAILURE
            
            Show
            bitwiseman Liam Newman added a comment - currentResult is reliable in the sense that it doesn't return null. However, it is still based on result . I've updated the referenced JIRA with additional details. As of Pipeline: Model Definition 1.1.9, when I run the following Pipeline: pipeline { agent any stages { stage ( 'Init' ) { steps { echo "Init result: ${currentBuild.result}" echo "Init currentResult: ${currentBuild.currentResult}" } post { always { echo "Post-Init result: ${currentBuild.result}" echo "Post-Init currentResult: ${currentBuild.currentResult}" } } } stage ( 'Build' ) { steps { echo "During Build result: ${currentBuild.result}" echo "During Build currentResult: ${currentBuild.currentResult}" sh 'exit 1' } post { always { echo "Post-Build result: ${currentBuild.result}" echo "Post-Build currentResult: ${currentBuild.currentResult}" } } } } post { always { echo "Pipeline result: ${currentBuild.result}" echo "Pipeline currentResult: ${currentBuild.currentResult}" } } } I get this output (trimmed for clarity): Init result: null Init currentResult: SUCCESS Post-Init result: null Post-Init currentResult: SUCCESS During Build result: null During Build currentResult: SUCCESS [test-pipeline] Running shell script + exit 1 Post-Build result: FAILURE Post-Build currentResult: FAILURE Pipeline result: FAILURE Pipeline currentResult: FAILURE ERROR: script returned exit code 1 Finished: FAILURE
            Hide
            jfemia James Femia added a comment -

            Please can this documentation include the information about it not being reliable inside a finally{} block, as described in the comments on JENKINS-47403?

            Show
            jfemia James Femia added a comment - Please can this documentation include the information about it not being reliable inside a finally{} block, as described in the comments on  JENKINS-47403 ?

              People

              • Assignee:
                Unassigned
                Reporter:
                bitwiseman Liam Newman
              • Votes:
                2 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated: