我刚刚开始使用GCP,只有几个云函数在工作,这些云函数的源代码在云源库中。架构就像,我们有一个单一的存储库,其中有多个文件夹,每个文件夹都有源代码,依赖项和每个云函数的凭据。到目前为止,我们正在手动部署云函数中的源代码,但最近我们开始使用云构建来创建CI/CD管道。我已经创建了一个触发器"push to master branch“,并使用cloudbuild.yaml作为配置文件。到目前为止,我的cloudbuild.yaml只有一个步骤,那就是找出哪个子文件夹获得了提交和部署,只部署那个特定的函数,而不是所有的云函数。这就是我面临的问题所在,该步骤运行得很好,但是没有部署云函数,当我检查日志时,我得到了日志,它将与yaml文件内容一起粘贴到下面。
steps:
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'bash'
args:
- -c
- |
for d in $(git diff --name-only --diff-filter=AMDR @~..@ | cut -d'/' -f 1);
do
echo $d;
cd $d
gcloud functions deploy $d --region=us-central1 --runtime=python37 --trigger-http --source=/workspace/.git/
cd ..
done
```
LOGS -
**starting build "2b5c5348-d946-41bb-87f7-fd98d7e2f2d9"
FETCHSOURCE
Initialized empty Git repository in /workspace/.git/
From https://source.developers.google.com/p/littleone-150007/r/testRepForAnalytics
* branch 677cf59b304d3b1b81488e48c1422cff9877824a -> FETCH_HEAD
HEAD is now at 677cf59 test
BUILD
Already have image (with digest): gcr.io/cloud-builders/gcloud
fatal: ambiguous argument '@~..@': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
PUSH
DONE
**发布于 2021-01-25 18:01:07
你对@~..@有意见。正如您所说,每个目录都有一个函数,为此,我建议您为每个函数目录创建一个cloudbuild.yaml,如下所示:
steps:
- name: "gcr.io/cloud-builders/gcloud"
args:
- functions
- deploy
- FUNCTION_NAME
- --runtime=YOUR_RUNTIME
- --trigger-http
- --region=europe-west1
- --memory=128MB
id: "deploying-a-function"
dir: "FUNCTION_DIR"然后,在云构建中为每个函数创建一个触发器,同时利用include files filter特性仅指定您想要监视的目录。就像如果在directry test中的函数,那么过滤器应该是test/**
https://stackoverflow.com/questions/65858307
复制相似问题