Vitaly Karasik DevOps
Vitaly Karasik DevOps

Reputation: 488

How to use Groovy variable into Extended Choice Jenkins Plugin?

I'd like to use a Groovy variable as a value for Extended Choice plugin. Seems trivial, but doesn't work - fails with "groovy.lang.MissingPropertyException: No such property: $COMPONENTS_LIST for class: groovy.lang.Binding".

Any ideas?

environment {
    COMPONENTS_LIST= "one two three"
}
parameters {
    extendedChoice (description: 'Components', multiSelectDelimiter: ' ', 
    name: 'Components_To_Deploy', quoteValue: false, saveJSONParameterToFile: false, type: 'PT_MULTI_SELECT', 
    value: $COMPONENTS_LIST, visibleItemCount: 3)
}

Upvotes: 1

Views: 1866

Answers (2)

SmartTom
SmartTom

Reputation: 821

I think that this is a syntax issue. You have to use double quote to refer to you variable :

def COMPONENTS_LIST= "one two three"
parameters {
    extendedChoice (description: 'Components', multiSelectDelimiter: ' ', 
    name: 'Components_To_Deploy', quoteValue: false, saveJSONParameterToFile: false, type: 'PT_MULTI_SELECT', 
    value: "${COMPONENTS_LIST}", visibleItemCount: 3)
}

Upvotes: 0

Marco R.
Marco R.

Reputation: 2720

It is a syntax error, you are trying to set the named parameter value to the content of the variable $COMPONENTS_LIST; which doesn't exist. Also there's a problem with the scope of the variable; which needs to be available in both closures. So try defining a variable outside the scope of both closure with the value you need and then use the variables inside the closures, as in the following example:

def componentsList = "one two three"
environment {
    COMPONENTS_LIST = componentsList
}
parameters {
    extendedChoice (description: 'Components', multiSelectDelimiter: ' ', 
    name: 'Components_To_Deploy', quoteValue: false, saveJSONParameterToFile: false, type: 'PT_MULTI_SELECT', 
    value: componentsList, visibleItemCount: 3)
}

Upvotes: 2

Related Questions