Jenkins

jenkins result vs. currentResult

thxxyj 2022. 12. 22. 14:45
728x90

https://shenxianpeng.github.io/2021/01/result-vs-currentresult/

 

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

 

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

 

1. stage-steps, post 단계에서

  • currentBuild.result는 전체 작업이 종료되기 전까지 return null
    그러나, 중간에 exit 되는 경우 null 이 아닌 작업 결과를 return 
  • currentBuild.currentResult는 작업이 종료되면 그 작업에 대한 결과를 return

 

2. post 단계에서는 result, currentResult 모두 작업에 대한 결과를 return

 

 

 

728x90