【发布时间】:2020-08-21 06:51:58
【问题描述】:
我一直试图在我的管道中调用另一个带有参数的 groovy 函数,但没有任何运气。
我将参数传递给的 groovy 函数由一个 bash 脚本组成,但是这个 bash 脚本无法识别我传递给它的参数。但是,如果我传递的参数在管道中定义为parameters {},那么它可以工作,但我不想要这个。
问题:
shell 脚本无法识别/理解参数,变量为空,没有值。
管道Jenkins.groovy
def call {
pipeline {
parameters {
string (name: VAR1, defaultValue: "Peace", description: '' } <--- This works, but not beneficial
string (name: VAR2, defaultValue: "Space", description: '' } <--- This works, but not beneficial
stages {
stage ('Run script') {
steps {
groovyFunction("${VAR1}", "${VAR2}")
groovyFunction("Peace", "Space") <--- WHAT I WANT
}
}
}
}
}
groovyFunction.groovy
def call(var1, var2) {
sh 'echo MY values ${var1} and ${var2}'
sh "echo MY values ${var1} and ${var2}" <-- Works using double quotes, this messes up sed and for-loops...
}
带有参数的管道输出:
MY values Peace and Space
不带参数的管道输出:
MY values and
我已尝试按照我上一个问题中的建议使用 environment{} 关键字,但没有任何运气。 Jenkins - environment
我知道存在类似的问题:
- Pass groovy variable to shell script
- How to assign groovy variable to shell variable
- Jenkins parameters
注意: 这接近于我提出的问题Shell parameter Jenkins
谢谢。
【问题讨论】:
标签: bash shell jenkins groovy jenkins-pipeline