通过API触发dbt Job:github_pull_request_id参数有效值咨询
解决dbt Cloud API触发Job时
github_pull_request_id参数无效的问题 问题描述
我希望在GitHub CI流水线中,当PR被批准时通过API触发dbt的CI Job。根据dbt Cloud API文档,触发Job有三个可选参数:git_sha、git_branch或github_pull_request_id。由于PR批准后GitHub会修改ref,无法直接使用git_branch;git_sha是可行方案,但我尝试使用github_pull_request_id参数时出现错误。
请求示例
curl --location 'https://cloud.getdbt.com/api/v2/accounts/acc_id/jobs/jb_id/run/' \ --header 'Authorization: Token token' \ --form 'cause="Triggered by GH Actions"' \ --form 'github_pull_request_id="3209"' \ --form 'schema_override="DBT_CLOUD_PR_81231_3209"'
错误信息
"github_pull_request_id": "'3209' is not valid under any of the given schemas"
解决方案
github_pull_request_id参数的预期值就是GitHub PR的编号(即你PR页面URL中的数字,比如https://github.com/owner/repo/pull/3209里的3209),问题出在参数的传递格式上:
dbt Cloud API要求该参数为整数类型,而你之前的请求通过--form传递了带引号的字符串值"3209",导致格式校验失败。
修改后的正确请求如下:
curl --location 'https://cloud.getdbt.com/api/v2/accounts/acc_id/jobs/jb_id/run/' \ --header 'Authorization: Token token' \ --form 'cause="Triggered by GH Actions"' \ --form 'github_pull_request_id=3209' \ --form 'schema_override="DBT_CLOUD_PR_81231_3209"'
只需去掉github_pull_request_id值的引号,直接传递数字即可。
内容的提问来源于stack exchange,提问作者LMF
相关产品推荐
相关产品推荐

