BRANCH = "develop"
BRANCH = "${BRANCH=="develop"?"null":"${BRANCH}"}"
print (BRANCH.getClass()) # class org.codehaus.groovy.runtime.GStringImpl
What is the correct syntax for null to be treated as a NUllObject? Expecting to return class org.codehaus.groovy.runtime.NullObject
CodePudding user response:
Your ternary currently returns a string with the characters null
, so you would need to need modify to:
BRANCH = BRANCH == 'develop' ? null : BRANCH
CodePudding user response:
As a very minimal example to actually run as a pipeline, you can use this:
pipeline {
agent any
stages {
stage('Hello') {
steps {
script {
def BRANCH = "develop"
BRANCH = "${BRANCH}" == "develop" ? null : "${BRANCH}"
print (BRANCH.getClass())
}
}
}
}
}