1

I'm trying to run a command which changes kubernetes cronjob image value as described here. But instead of typing this command to cmd i'm trying to run it via Container Registry's build trigger.

I tried ' and \ as escape chars.

  steps:
     - name: 'gcr.io/cloud-builders/kubectl'
      args: [
      "patch",
       "cronjob",
       "cron-history-orders",
       "--type=json",
      "-p=[{'"op'":'"replace'",'"path'":'"/spec/jobTemplate/spec/template/spec/containers/0/image'",'"value'":'"python:3.5'"}]"
       ]
      env:  ['CLOUDSDK_COMPUTE_ZONE=europe-west3-c','CLOUDSDK_CONTAINER_CLUSTER=xxx-prod']

or when I try

   "-p='[{\"op\":\"replace\", \"path\": \"/spec/jobTemplate/spec/template/spec/containers/0/image\", \"value\":\"python:3.5\"}]'"

or

  "-p='[{'op':'replace','path':'/spec/jobTemplate/spec/template/spec/containers/0/image','value':'python:3.5'}]'"

I get error loading template: json: cannot unmarshal object into Go value of type []json.RawMessage

Tamer Aktaş
  • 416
  • 4
  • 13
  • The link that you are referring is about updating the deployment with the new built image, however the Container Registry build trigger is for building the new image. If you can provide more information on what you’re trying to, that would help to propose some solutions. – KarthickN Feb 07 '18 at 05:05

1 Answers1

2

As you no doubt realize, the challenge here is that you are dealing with layers of escaping -- your yaml contains json that will be passed on a command line.

I was able to pass this command through with this yaml:

steps:
- name: 'gcr.io/cloud-builders/kubectl'
  args: [ "patch", "cronjob", "cron-history-orders", "--type=json", "-p='[{\"op\":\"replace\", \"path\": \"/spec/jobTemplate/spec/template/spec/containers/0/image\", \"value\":\"python:3.5\"}]'" ]
  env:  ['CLOUDSDK_COMPUTE_ZONE=europe-west3-c','CLOUDSDK_CONTAINER_CLUSTER=xxx-prod']
David Bendory
  • 1,258
  • 8
  • 14