Ryan Johnson
Ryan Johnson

Reputation: 109

Jenkins retrieve active choice parameter in groovy script

I have one Active Choice Parameter called ENVIRONMENT. I want to use that parameter in my next Active Choice Parameter. How do I retrieve the previous choice?

Here is my code. I cannot figure out how to retrieve the ENVIRONMENT variable from the previous parameter and assign it to my env variable in my new groovy script for my second variable.

import groovy.sql.Sql

String env = $ENVIRONMENT

def output = []
def db = [url:'jdbc:oracle:thin:@database_host:1521:SID', user:'username', password:'password', driver:'oracle.jdbc.OracleDriver']
def sql = Sql.newInstance(db.url, db.user, db.password, db.driver)
String sqlString = ("select distinct logical_host from SERVER_NAME_VW where app='ME' and env = ${env} order by 1")

sql.eachRow(sqlString){ row ->  
    output.push(row[0])
}

return output

Upvotes: 3

Views: 14018

Answers (1)

pczeus
pczeus

Reputation: 7867

You are using the incorrect parameter type for the job.

You need to change the parameter type to

Active Choices Reactive Reference Parameter

Which allows you to add the ENVIRONMENT parameter as a referenced parameter.
For more information, see the Active Choices Plugin documentation

Upvotes: 6

Related Questions