GCP Cloud Build deploying a scheduler job

12 Views Asked by At

We have the following in our cloudbuild.yaml file and it is creating our cloud scheduler job as expected.

- name: gcr.io/cloud-builders/gcloud
  args: ['scheduler', 'jobs', 'create', 'http', 'test-job',
            '--schedule', '30 1 * * 7',
            '--time-zone', 'Asia/Taipei',
            '--uri', 'MyURI',
            '--message-body', 'msg payload',
            '--location', 'asia-east1',
            '--oauth-service-account-email', 'service_account_name',
    ]

But when we trigger the cloud build again, since the job has already created, the code failed. Instead of creating, the code need to be modified manually

- name: gcr.io/cloud-builders/gcloud
  args: ['scheduler', 'jobs', 'update', 'http', 'test-job',
            '--schedule', '30 1 * * 7',
            '--time-zone', 'Asia/Taipei',
            '--uri', 'MyURI',
            '--message-body', 'msg payload',
            '--location', 'asia-east1',
            '--oauth-service-account-email', 'service_account_name',
    ]

We would like to keep both of these in our cloudbuild.yaml by using if-else expression rather than manually edit the args. How would we, if possible, restructure the build steps in Build configuration file schema (Build config file schema) that would check if the job exists, if not create. If job exists and no changes, continue. If changes are present then update.

0

There are 0 best solutions below