Automate Docker build using Cloud Build

I was trying to create trigger for my cloud build and set my cloudbuild.yaml but keeps this error L:Failed to trigger build: generic::invalid_argument: if ‘build.service_account’ is specified, the build must either (a) specify ‘build.logs_bucket’, (b) use the REGIONAL_USER_OWNED_BUCKET build.options.default_logs_bucket_behavior option, or (c) use either CLOUD_LOGGING_ONLY / NONE logging options

I set my cloudbuild.yaml this way:

steps:

build the container image

args: [“build”, “-t”, “gcr.io/$PROJECT_ID/gcpdevops”, “.”]

images:

Please help me…

Is this related to one of our courses? If so, please give me a link to the course and lab, so I have a bit more context.

sure,in GCP DevOps Project>sprint 04>lesson 6 ==>this link
https://learn.kodekloud.com/user/courses/gcp-devops-project/module/f84d8c20-935f-462e-9503-94408617064a/lesson/fa0ed760-ba86-4c44-a074-b6404b10f8c4

I followed all the script from instructor but gives me error which I shared with you earlier.

To make sure your yaml is actually correct, I’ll need you to paste it in again using

# paste your yaml as a code block. Use the </> key to generate the block!!

I’m not sure what was done in the previous lectures to prepare things for using cloudbuild; but having the valid YAML is going to be a first step.

this is code for cloudbuild.yaml

steps:

Build the container image

  • name: “gcr.io/cloud-builders/docker
    args: [“build”, “-t”, “us-central1-docker.pkg.dev/$PROJECT_ID/testrepo/gcpdevops”, “.”]

images:

  • “us-central1-docker.pkg.dev/$PROJECT_ID/testrepo/gcpdevops”

I hit the same error. The quickest way to work around this is to add the CLOUD_LOGGING_ONLY option to your cloudbuild.yaml file. When you do that, the YAML file looks like this:

steps:
- name: 'docker'
  args: ['build', '-t', 'gcr.io/$PROJECT_ID/gcpdevops', '.']
images:
- 'gcr.io/$PROJECT_ID/gcpdevops'
options:
  logging: CLOUD_LOGGING_ONLY 

I noticed in the course that no account was selected during the creation of trigger. This is no longer an option. You will need to select at least the service account for your project which will likely be the default choice.