如何从命令行设置/获取json格式的气流变量

编程入门 行业动态 更新时间:2024-10-19 11:52:00
本文介绍了如何从命令行设置/获取json格式的气流变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我无法通过云外壳以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格式的气流变量

本文发布于:2023-11-23 19:57:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622699.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:气流   变量   命令行   格式   json

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!