gpt4 book ai didi

google-cloud-build - CloudBuild 作业未并行执行

转载 作者:行者123 更新时间:2023-12-05 01:14:20 26 4
gpt4 key购买 nike

我正在学习 CloudBuild,并了解我可以使用 waitFor 来影响构建运行的顺序。 job1 包含一些 sleep 时间来模拟长时间运行的作业。 job2 只是回应了一些东西。 done 等待 job1job2。所以我创建了一个这样的测试版本:我有一个 package.json

{
"scripts": {
"job1": "echo \"[job1] Starting\" && sleep 5 && echo \"[job1] ...\" && sleep 2 && echo \"[job1] Done\" && exit 0",
"job2": "echo \"[job2] Hello from NPM\" && exit 0",
"done": "echo \"DONE DONE DONE!\" && exit 0"
},
}

Job 1 模拟一个长时间运行的作业,我在其中跳跃作业 2 将并行执行。但似乎输出显示它不是。 CloudBuild 是否一次只运行 1 个步骤?

cloudbuild.yaml

steps:
- name: 'gcr.io/cloud-builders/npm'
args: ['run', 'job1']
id: 'job1'
- name: 'gcr.io/cloud-builders/npm'
args: ['run', 'job2']
id: 'job2'
- name: 'gcr.io/cloud-builders/npm'
args: ['run', 'done']
waitFor: ['job1', 'job2']

输出

Operation completed over 1 objects/634.0 B.                                      
BUILD
Starting Step #0 - "job1"
Step #0 - "job1": Already have image (with digest): gcr.io/cloud-builders/npm
Step #0 - "job1":
Step #0 - "job1": > learn-gcp@1.0.0 job1 /workspace
Step #0 - "job1": > echo "[job1] Starting" && sleep 5 && echo "[job1] ..." && sleep 2 && echo "[job1] Done" && exit 0
Step #0 - "job1":
Step #0 - "job1": [job1] Starting
Step #0 - "job1": [job1] ...
Step #0 - "job1": [job1] Done
Finished Step #0 - "job1"
Starting Step #1 - "job2"
Step #1 - "job2": Already have image (with digest): gcr.io/cloud-builders/npm
Step #1 - "job2":
Step #1 - "job2": > learn-gcp@1.0.0 job2 /workspace
Step #1 - "job2": > echo "[job2] Hello from NPM" && exit 0
Step #1 - "job2":
Step #1 - "job2": [job2] Hello from NPM
Finished Step #1 - "job2"
Starting Step #2
Step #2: Already have image (with digest): gcr.io/cloud-builders/npm
Step #2:
Step #2: > learn-gcp@1.0.0 done /workspace
Step #2: > echo "DONE DONE DONE!" && exit 0
Step #2:
Step #2: DONE DONE DONE!
Finished Step #2
PUSH
DONE

最佳答案

如果您希望 job2job1 同时执行,您应该添加以下行

waitFor: ['-'] 在您的 cloudbuild.yaml 中,紧接在 job2 之后。正如 official documentation 中所述:

If no values are provided for waitFor, the build step waits for all prior build steps in the build request to complete successfully before running.

To run a build step immediately at build time, use - in the waitFor field.

The order of the build steps in the steps field relates to the order in which the steps are executed. Steps will run serially or concurrently based on the dependencies defined in their waitFor fields.

在文档中,还有一个 example关于如何并行运行两个作业。

如果你想让 job2 和 job1 一起运行,你应该有这样的东西:

steps:

- name: 'gcr.io/cloud-builders/npm'
args: ['run', 'job1']
id: 'job1'
- name: 'gcr.io/cloud-builders/npm'
args: ['run', 'job2']
id: 'job2'
waitFor: ['-'] # The '-' indicates that this step begins immediately.
- name: 'gcr.io/cloud-builders/npm'
args: ['run', 'done']
waitFor: ['job1', 'job2']

另请注意 maximum number of concurent builds你可以使用 10。

关于google-cloud-build - CloudBuild 作业未并行执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58811564/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com