How to set current build result in Pipeline?

Issue

  • Whenever I print out the field: currentBuild.result it is null. When does this get set or am I supposed to set it?

Environment

  • CloudBees Jenkins Enterprise
  • Pipeline

Resolution

Avoiding setting currentBuild.result manually. Instead use the catchError step in Scripted Pipeline, or a post block in Declarative.

Have more questions?

5 Comments

  • 0
    Avatar
    Kenneth Lamb

    Where can I find a list of valid values for currentBuild.result? I thought it was just a string, but it appears to only allow certain values.

    For example, this code:
       echo "currentBuild.result1: '${currentBuild.result}'"
       currentBuild.result = 'FAILEDZZZZ'
       echo "currentBuild.result1: '${currentBuild.result}'"

    Will yield this:   

    currentBuild.result1: 'null'
    [Pipeline] echo
    currentBuild.result1: 'FAILURE'

     

  • 3
    Avatar
    Allan Burdajewicz

    Hi Kenneth,

    You are right. currentBuild.result is not a simple String. It is a String representation of hudson.model.Result

    The reason why you see FAILURE when the String does not match a known value is because of this method.

    Regards,

    Edited by Allan Burdajewicz
  • 0
    Avatar
    Kenneth Lamb

    Just what I was looking for. Thank you very much!

  • 0
    Avatar
    Lee Meador

    Just for making it easy there are two other interesting statuses ABORTED and UNSTABLE

  • 0
    Avatar
    Luis a. Del Pozo G.

    Hello everyone :) !!

    I am new to jenkins and groovy and I'm trying to print out using this same example other values such as

    currentBuild.durationString and others, I have followed this example 
    and the one from
    https://plugins.jenkins.io/logstash/, trying to print out the currentBuild.durationString
    like result in data, it that possible to do, any suggestions of how can I
    accomplish it?, Any help is really appreciated.

    Thank you very much and good day!
Please sign in to leave a comment.