【问题标题】:How to execute shell script in jenkins Active Choice Parameter so that I can get the dynamic inputs如何在jenkins Active Choice Parameter中执行shell脚本,以便我可以获得动态输入
【发布时间】:2022-08-11 21:08:38
【问题描述】:
我尝试在 Jenkins 的 Active Choice Parameter 中使用以下脚本获取当前工作目录,但它没有提供任何输出。回退脚本也没有被调用
def command = \"pwd\"
def proc = command.execute()
proc.waitFor()
def output = proc.in.text
def exitcode = proc.exitValue()
def error = proc.err.text
println \"${output}\"
标签:
jenkins
jenkins-pipeline
jenkins-plugins
jenkins-groovy
【解决方案1】:
该脚本将在 Jenkins 中的 http://jenkins-url/script 脚本控制台中很好地运行,但在主动选择中,您不需要打印输出,而是可以从脚本返回输出,因此参数将获取值。
def command = "pwd"
def proc = command.execute()
proc.waitFor()
def output = proc.in.text
def exitcode = proc.exitValue()
def error = proc.err.text
return [output]
在詹金斯管道中,您可以打印参数的值,如下所示 -
假设您已在活动选择中定义参数名称为 param1,您可以在管道中获取值,如下所示 -
pipeline {
agent any
stages {
stage('sample active choice') {
steps {
echo "Param value is ${param1}"
}
}
}
}