Skip to main content
Background Image
  1. Posts/

What's the difference between result and currentResult in Jenkins?

·336 words·2 mins· ·
Xianpeng Shen
Author
Xianpeng Shen
Table of Contents

This is just a note to myself about the difference between Jenkins result and currentResult.

Declarative Pipeline
#

Here is a test code from this ticket JENKINS-46325

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

Output

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

Scripted Pipeline
#

Here is a test code from cloudbees support case

Example that forces a failure then prints result:

node {
    try {
        // do something that fails
        sh "exit 1"
        currentBuild.result = 'SUCCESS'
    } catch (Exception err) {
        currentBuild.result = 'FAILURE'
    }
    echo "RESULT: ${currentBuild.result}"
}

Output:

Started by user anonymous
[Pipeline] Allocate node : Start
Running on master in /tmp/example/workspace/test
[Pipeline] node {
[Pipeline] sh
[test] Running shell script
+ exit 1
[Pipeline] echo
RESULT: FAILURE
[Pipeline] } //node
[Pipeline] Allocate node : End
[Pipeline] End of Pipeline
Finished: FAILURE

Example that doesn’t fail then prints result:

node {
    try {
        // do something that does not fail
        echo "Im not going to fail"
        currentBuild.result = 'SUCCESS'
    } catch (Exception err) {
        currentBuild.result = 'FAILURE'
    }
    echo "RESULT: ${currentBuild.result}"
}

Output:

Started by user anonymous
[Pipeline] Allocate node : Start
Running on master in /tmp/example/workspace/test
[Pipeline] node {
[Pipeline] echo
Im not going to fail
[Pipeline] echo
RESULT: SUCCESS
[Pipeline] } //node
[Pipeline] Allocate node : End
[Pipeline] End of Pipeline
Finished: SUCCESS

Related

Jenkins Multibranch Pipeline
·405 words·2 mins
Discusses the use of Jenkins Multibranch Pipeline to manage multiple branches in a project, enabling parallel builds for pull requests and efficient code review processes.
Jenkins Linux agent configuration
·298 words·2 mins
Provides a step-by-step guide on how to configure a Jenkins Linux agent, including setting up the Java runtime, creating the node, and troubleshooting common issues.
Jenkins Windows agent configuration
·544 words·3 mins
Provides a step-by-step guide on how to configure a Jenkins Windows agent, including setting up the Java runtime, creating the node, and troubleshooting common issues.
How to backup Jenkins
·214 words·2 mins
This article explains how to backup Jenkins using the ThinBackup plugin and shell scripts, ensuring that your Jenkins configuration and build data are safely stored.
How to fix ".NET Framework 2.0 or later is required on this computer to run a Jenkins agent as a Windows service"
·211 words·1 min
Resolve the issue of Jenkins Windows agents not connecting due to missing .NET Framework, including steps to install .NET Framework 3.5 and set up the Jenkins agent service.
Jenkins Top 3 best practice
·906 words·5 mins
Discusses three best practices for Jenkins: Configuration as Code, Shared Libraries, and Multi-Branch Pipeline, highlighting their benefits in terms of transparency, traceability, and self-service builds.