Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 312
Ryan Johnson Avatar asked Mar 04 '26 05:03

Ryan Johnson


1 Answers

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

like image 166
pczeus Avatar answered Mar 06 '26 18:03

pczeus