我无法通过云外壳以json格式编辑气流变量的值.
I can't edit values of airflow variables in json format through cloud shell.
我正在使用云外壳访问气流变量参数(以json格式),当我使用以下命令时,它会为我提供完整的json:
I am using cloud shell to access my airflow variable params (in json format) and it gives me the complete json when i use following command:
gcloud composer environments run composer001 --location us-east1 variables --get params但是我想编辑json中的值之一,我该如何访问它?
However I want to edit one of the values inside json, how do i access that?
我参考了文档以及Google上的各种其他链接,但是只能找到如何设置不是json格式而是单值变量的变量.
I referred to the documentation and various other links on google however could only find how to set variables that are not in json format but are a single value variables.
推荐答案Cloud Composer CLI和Airflow CLI仅对顶级变量起作用,而不对它们的JSON内容起作用.
Cloud Composer CLI and Airflow CLI only operate on top-level variables, not their JSON contents.
您可以使用Airflow UI来编辑JSON变量,因为UI加载了整个变量,您可以就地对其进行编辑.或者,如果您需要通过命令行更新JSON变量中的特定值,则可以先将变量导出到JSON文件:
You can use Airflow UI to edit your JSON variable, as the UI loads the whole variable and you can edit it in place. Or if you need to update a specific value inside your JSON variable through command line, you can first export your variables to a JSON file:
gcloud composer environments run \ [ENVIRONMENT] --location [LOCATION] \ variables -- --export /home/airflow/gcs/data/your-vars.json gcloud composer environments storage data export \ --environment [ENVIRONMENT] --location [LOCATION] \ --source your-vars.json --destination .使用类似 jq 的命令编辑JSON中的值:
edit the value inside JSON using a command like jq:
jq '.params.jsonkey = "newvalue"' your-vars.json > your-updated-vars.json并将更新的文件导入回Cloud Composer:
and import the updated file back to Cloud Composer:
gcloud composer environments storage data import \ --environment [ENVIRONMENT] --location [LOCATION] \ --source your-updated-vars.json gcloud composer environments run \ [ENVIRONMENT] --location [LOCATION] \ variables -- --import /home/airflow/gcs/data/your-updated-vars.json更多推荐
如何从命令行设置/获取json格式的气流变量
发布评论