I've been trying to call another groovy function with parameters inside my pipeline without any luck.
The groovy function I am passing the parameters to consists of a bash script, but this bash script does not recognize the parameter(s) I am passing to it. If however the parameter passed by i defined as a parameters {}
in the pipeline, then it works, but I do not want this.
PROBLEM:
The shell script does not recognize/understand the arguments, the variables are empty, no value.
pipelineJenkins.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...
}
OUTPUT FROM PIPELINE WITH PARAMETERS:
MY values Peace and Space
OUTPUT FROM PIPELINE WITHOUT PARAMETERS:
MY values and
I have tried using the environment{}
keyword as suggested in my previous question, without any luck. Jenkins - environment
I am aware that there are similar issues out there:
- Pass groovy variable to shell script
- How to assign groovy variable to shell variable
- Jenkins parameters
NOTE: This is close to a duplicate of my asked quesiton Shell parameter Jenkins
Thanks.