Define a variable and set it to a default value if something goes wrong during definition

All you need is some regular Java/Groovy code:

def jenkinsBuild = System.getenv("BUILD_NUMBER") ?: "0"

The code above uses Groovy’s “elvis” operator, and is a shorthand for the following code, which uses Java’s ternary operator:

def buildNumber = System.getenv("BUILD_NUMBER")
def jenkinsBuild = buildNumber != null ? buildNumber : "0"

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)