Use environment variable with oc patch

608 views Asked by At

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 '$' 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

1

There are 1 answers

1
Rakesh Gupta On

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'"}}}}}'