0

How to reference the variable inside the map . When I do this I only get literal string dcihub_sonar_binaries, while I expect the else rule to result to value of dcihub_sonar_binaries.

  dcihub_sonar_binaries = '$WORKSPACE/tenants/dcihub/ui.apps/target/,$WORKSPACE/tenants/dcihub/ui.config/target/,$WORKSPACE/tenants/dcihub/ui.content/target/'
def CODEBASE = "dcihub"
    def SonarValues = [:]
    if (CODEBASE == "platform") {
        SonarValues = ["platform": [platform_sonar_exclusion, platform_sonar_binaries]]

    } else {
        SonarValues.put(CODEBASE, "${CODEBASE}_sonar_binaries")
    }
    return SonarValues
}

When I print it. That is the ouput.

dcihub_sonar_binaries

Expected output :

'$WORKSPACE/tenants/dcihub/ui.apps/target/,$WORKSPACE/tenants/dcihub/ui.config/target/,$WORKSPACE/tenants/dcihub/ui.content/target/'

WhoAmI
  • 1,013
  • 2
  • 9
  • 19

1 Answers1

0

I don't see how/where variable is declared.

If it's a local variable inside function/method then no way to reference it - think about storing all required values in map.

If it's a script/object variable/property then this should work:

this."${CODEBASE}_sonar_binaries" 

Instead of this there could be any object where the variable/property is declared.

For example this script prints Hello world!

hello_world="Hello world!"
def suffix = 'world'
println this."hello_${suffix}"

But this fails because hello_world will be a part of hidden run() function:

def hello_world="Hello world!"
def suffix = 'world'
println this."hello_${suffix}"
daggett
  • 26,404
  • 3
  • 40
  • 56