简体   繁体   English

Jenkins 在 groovy 脚本中检索活动选择参数

[英]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.

相关问题 如何使用 Jenkins 主动选择参数 groovy 脚本在远程服务器中执行 shell 脚本? - How to execute shell script in remote server using Jenkins Active choice parameter groovy script? 如何在 Jenkins 的活动选择参数中将简单的 shell 命令作为常规脚本执行? - How do I execute a simple shell-command as a groovy script in the active choice parameter in Jenkins? Jenkins Groovy 主动选择反应参数引用的参数创建错误 - Jenkins Groovy Active Choice Reactive Parameter referenced parameter creates error Active Choice 参数中的 Groovy - Groovy in Active Choice Parameter Jenkins Active选择参数,如何使用groovy执行aws shell命令 - Jenkins Active choice parameter, how to execute aws shell command with groovy 在 Jenkins 主动选择反应参数中使用 Groovy 执行 AWS KMS 命令 - Executing a AWS KMS command with Groovy in a Jenkins Active Choice Reactive Parameter 使用Groovy脚本解析Jenkins中动态选择参数的文件名 - Parsing file name for Dynamic Choice Parameter in Jenkins with a Groovy script 未填充动态选择参数:Jenkins作业+ Groovy脚本 - Dynamic Choice Parameter not populated: Jenkins job + Groovy script 如何将默认值 Jenkins 活动选择参数设置为脚本 - How to set default value Jenkins active choice parameter as a script Jenkins:从Active Choices参数groovy脚本访问其他插件 - Jenkins: Accessing other plugins from Active Choices Parameter groovy script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM