在 YAML 文件中传递 json-string 命令参数 [英] Passing a json-string command arg in a YAML file

查看:24
本文介绍了在 YAML 文件中传递 json-string 命令参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行一个命令来更改 kubernetes cronjob 图像值,如这里.但是我没有在 cmd 中输入这个命令,而是尝试通过 Container Registry 的构建触发器来运行它.

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

或者当我尝试

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

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

我收到 error loading template: json: cannot unmarshal object into Go value of type []json.RawMessage

推荐答案

正如您无疑意识到的那样,这里的挑战是您正在处理转义层——您的 yaml 包含将在命令行上传递的 json.

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.

我能够通过这个 yaml 传递这个命令:

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

这篇关于在 YAML 文件中传递 json-string 命令参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆