[英]Jenkins retrieve active choice parameter in groovy script
I have one Active Choice Parameter called ENVIRONMENT.我有一个名为 ENVIRONMENT 的主动选择参数。 I want to use that parameter in my next Active Choice Parameter.我想在下一个 Active Choice 参数中使用该参数。 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.我无法弄清楚如何从前一个参数中检索 ENVIRONMENT 变量并将其分配给我的第二个变量的新 groovy 脚本中的 env 变量。
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
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.这允许您添加 ENVIRONMENT 参数作为引用参数。
For more information, see the Active Choices Plugin documentation有关更多信息,请参阅Active Choices 插件文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.