【问题标题】:GCP Cloud Build - deploying a scheduler jobGCP Cloud Build - 部署调度程序作业
【发布时间】:2020-05-30 12:25:44
【问题描述】:

我们的 cloudbuild.yaml 文件中有以下内容,它正在按预期创建我们的云调度程序作业。

    steps:
    # deploy cloud scheduler job
    - name: "gcr.io/cloud-builders/gcloud"
      args: ["scheduler", "jobs", "create", "pubsub", "my_job_name", "--schedule=0 0 * * 1-5", "--topic=my_topic", "--message-body=My Message", "--description=My Description", "--time-zone=America/MyTimeZone"]

但是,一旦再次触发云构建,我们就会收到以下错误:

    ERROR: (gcloud.scheduler.jobs.create.pubsub) ALREADY_EXISTS: ....

我们希望将其保留在我们的 cloudbuild 中,而不是在控制台中手动创建。如果可能,我们将如何重组构建步骤和/或在 python37 中添加一个云函数来检查作业是否存在,如果不创建。如果作业存在且没有更改,请继续。如果存在更改,则更新。

我们将不胜感激提供任何反馈、建议或示例!

谢谢

【问题讨论】:

  • 在创建具有给定名称的作业之前删除具有给定名称的作业的步骤怎么样?
  • @Kolban 这可能是一个可行的解决方案。我会和我的团队核实一下。谢谢!

标签: google-cloud-platform google-cloud-functions google-cloud-build google-cloud-scheduler


【解决方案1】:

我正在使用管道来忽略此错误。如果调度程序已经存在,它只会打印出错误并继续构建。

- name: 'gcr.io/cloud-builders/gcloud'
  id: scheduler
  waitFor: ['sensor']
  entrypoint: bash
  args:
   - '-c'
   - |
      gcloud scheduler jobs create http NAME --schedule="* * * * *" --uri="uri" ||  echo "Scheduler email-sensor already exist";

不是最好的解决方案,但它有效。

【讨论】:

    【解决方案2】:

    您可以在 cloudbuild.yaml 中使用 gcloud Cloud Builder 和 bash 构建条件。请参阅this creative answer 获取灵感。

    I.E.在创建计划之前,您使用带有gcloud beta scheduler jobs list 和/或gcloud beta scheduler jobs describe 的检查作为条件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-26
      • 1970-01-01
      • 2021-03-29
      • 2021-01-22
      • 2019-07-22
      • 1970-01-01
      • 1970-01-01
      • 2021-04-06
      相关资源
      最近更新 更多