对文件夹中的所有文件运行终端命令
我有一个 models 文件夹,其中包含一堆 sql 文件 models/mart/table1.sql
、models/mart/table2.sql
、models/mart/table3 .sql
我在终端上手动运行此命令:
dbt run-operation generate_model_yaml --args '{"model_name": "table1"}'
但是,我不想为每个表单独运行它,而是想将其包含在 Bitbucket 管道中。如何修改该命令,使其在循环中运行?它应该从指定文件夹(models/mart)中提取所有文件的表名(文件名),然后通过每次用文件名替换 model_name 来相应地运行命令?
pipelines:
custom:
dbt-run-default:
- step:
name: 'Compile'
image: fishtownanalytics/dbt:1.0.0
script:
- cd dbt_4flow
- dbt deps --profiles-dir ./profiles
I have a models folder which contains a bunch of sql files models/mart/table1.sql
, models/mart/table2.sql
, models/mart/table3.sql
I run this command manually on the terminal:
dbt run-operation generate_model_yaml --args '{"model_name": "table1"}'
However, instead of running it individually for each table, I want to include it in the Bitbucket pipeline. How can I modify the command such that it runs in a a loop? It should extract the tablename (filename) for all files from a specified folder (models/mart) and then run the command accordingly by replacing the model_name by the filename each time?
pipelines:
custom:
dbt-run-default:
- step:
name: 'Compile'
image: fishtownanalytics/dbt:1.0.0
script:
- cd dbt_4flow
- dbt deps --profiles-dir ./profiles
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个 Shellcheck - 干净的代码:
shopt -s nullglob
可防止代码中的"$sql_dir"/*.sql
扩展为垃圾。${sql_path##*/}
和${sql_name%.sql}
的解释。Try this Shellcheck-clean code:
shopt -s nullglob
prevents the"$sql_dir"/*.sql
in the code expanding to garbage if there are no '.sql' files in the directory.${sql_path##*/}
and${sql_name%.sql}
.