Cloud Build无法读取公开GitHub仓库中的cloudbuild.yaml配置文件
问题原因与解决方案
你遇到的问题核心是对gcloud builds submit的两个参数理解有偏差:
--git-source-dir仅指定远程仓库中作为构建上下文的子目录(构建过程中会将该目录内容作为工作基础),但不会改变--config参数的路径解析规则。--config默认从本地执行命令的目录查找文件,而非远程仓库的目录,所以你指定terraform/cloudbuild.yaml时,gcloud会在本地找这个路径,而非远程仓库内的对应位置,自然报错。
两种可行的解决方法
方法1:直接指定配置文件的远程RAW URL
把--config指向仓库中cloudbuild.yaml的Raw文件地址,命令如下:
gcloud builds submit https://github.com/GoogleCloudPlatform/cloud-builders-community \ --region="$REGION" \ --git-source-revision=master \ --git-source-dir=terraform \ --config=https://raw.githubusercontent.com/GoogleCloudPlatform/cloud-builders-community/master/terraform/cloudbuild.yaml
方法2:使用仓库URL的扩展语法指定配置文件
在远程仓库URL后通过#拼接分支:配置文件路径,直接告诉gcloud从仓库内指定位置读取配置,命令如下:
gcloud builds submit https://github.com/GoogleCloudPlatform/cloud-builders-community#master:terraform/cloudbuild.yaml \ --region="$REGION" \ --git-source-dir=terraform
这两种方法都不需要本地克隆仓库,完全通过远程提交完成构建。
内容的提问来源于stack exchange,提问作者John Velonis
相关产品推荐
相关产品推荐

