use environnement variable with oc patch

8/4/2021

I am currently trying to modify my image:tag in my build config from shell command using oc patch.
My command is as such :

oc patch bc/my-bc-name --patch '{"spec":{"strategy":{"sourceStrategy":{"from":{"name": "image:tag" }}}}}'

what i want to do :

oc patch bc/my-bc-name --patch '{"spec":{"strategy":{"sourceStrategy":{"from":{"name": $myImage }}}}}'

such that the image name is specify as an environnement variable. Unfortunately, i got : Error from server (BadRequest): invalid character '

#x27; looking for beginning of value

using simple/double quote nor ${myImage} does not seems to work as well.

any workaround to bypass this is more than welcomed :)

Kind regards

-- Jason dricks
buildconfig
kubernetes
openshift

1 Answer

8/4/2021

Surround your environment variable with single quotes as shown below. This will allow the shell to replace/expand it with its value.

oc patch bc/my-bc-name --patch '{"spec":{"strategy":{"sourceStrategy":{"from":{"name": "'$myImage'"}}}}}'
-- Rakesh Gupta
Source: StackOverflow