In my scripted pipeline, I have a shell script that performs helm upgrade and I have also set some environment variables like below:
sh """helm upgrade --install ${someVar} chart-hub/java-${javaVersion} \
...
--set env.vars[1] .name=some_name_here \
--set env.vars[1] .value="123abcdefhgj3457u" \
--set env.vars[2] .name=some_other_name_here \
--set env.vars[2] .value="true"
...
Things were working well until I added --set env.vars[2] .name=some_other_name_here \
and
--set env.vars[2] .value="true"
to my pipeline script . I am getting the error ...ReadString: expects " or n but found t, error found in #10 byte of ...|, "value":true}], ...
I have tried enclosing the value like: 'true'
, "'true'"
and even storing true
in a variable and then assigning the variable to --set env.vars[2] .value="${myVar}" but the error persists.
Any idea what I'm doing wrong, or solutions I could try? Thanks in advance
CodePudding user response:
This sounds like the type casting from Groovy to shell to Golang between the interpreters is recasting the string to a boolean. I would heavily suspect the shell interpreter is recasting the type. You can bypass the type recasting by writing your values to a in-workspace YAML file to be passed as an input to Helm.
First, we need to construct the map:
Map helmValues = ['env':
['vars': [
['name': 'some_name_here', 'value': '123abcdefhgj3457u'],
['name': 'some_other_name_here', 'value': 'true']
]]
]
This is a Map[Map[List[Map[String, String]]]]
type, where the outer map is your env
, the inner map is your vars
, the list of maps is your names
and values
pairs, and the strings are your values for the names and values. It is unfortunate that the Helm chart uses this structure for its inputs due to the complexity.
You can then write the Map to a YAML file in the workspace with the writeYaml
step method from the pipeline-utility-steps plugin:
writeYaml(file: 'values.yaml', data: helmValues)
You can now use this YAML file as inputs to helm upgrade
in the expected manner:
sh(label: "Helm Upgrade ${someVar} Java", script: "helm upgrade -f values.yaml --install ${someVar} chart-hub/java-${javaVersion}")
Putting it all together:
steps {
Map helmValues = ['env':
['vars': [
['name': 'some_name_here', 'value': '123abcdefhgj3457u'],
['name': 'some_other_name_here', 'value': 'true']
]]
]
writeYaml(file: 'values.yaml', data: helmValues)
sh(label: "Helm Upgrade ${someVar} Java", script: "helm upgrade -f values.yaml --install ${someVar} chart-hub/java-${javaVersion}")
}
CodePudding user response:
To remove the error ReadString: expects " or n but found t, error found in #10 byte of ...|, "value":true}], ...
Enclosing the true value like '"true"'
worked for me.