NickS
NickS

Reputation: 84

Null comparison not working with jenkins groovy script

I have a small code snippet here

                            pom = readMavenPom file: 'pom.xml'
                            def dataModelVersion = "${pom.properties['data-model.version']}"
                            def item = [("${pom.artifactId}"): "${dataModelVersion}"]
                            if(dataModelVersion!=null){
                                theMap.putAll(item)
                            }

Not every pom has a data-model.version value, so it seems like dataModelVersion should contain null which it appears to when I check my map, but for some reason everything is added to the map with that condition, if I change it to dataModelVersion==null to see if I can at least get all null values added nothing gets added

the map will then contain items like

vessel-dataset: null
vessel-storage: 0.1.18
simulation: null

What am I missing here, I feel like I've tried everything

Upvotes: 0

Views: 2097

Answers (1)

daggett
daggett

Reputation: 28599

you are assigning to a dataModelVersion String (GString) in this line:

def dataModelVersion = "${pom.properties['data-model.version']}"

and if pom.properties['data-model.version'] returns null

then dataModelVersion == "null"


so just change it

def dataModelVersion = pom.properties['data-model.version']

Upvotes: 1

Related Questions