atgobal
atgobal

Reputation: 35

How to fully automate the Google Cloud Build trigger creation

i try to fully automate the cloud build trigger creation via sh script

As source I use Github.

So far it's possible to create the trigger

gcloud beta builds triggers create github \
  --repo-name=organisation/repo \
  --repo-owner=organisation \
  --branch-pattern="^main$" \
  --build-config=cloudbuild.yaml

BUT each repo has to be authorized manually before otherwise you get the Error:

ERROR: (gcloud.beta.builds.triggers.create.github) FAILED_PRECONDITION: Repository mapping does not exist. Please visit https://console.cloud.google.com/cloud-build/triggers/connect?project=********* to connect a repository to your project

Which links me to the UI to create the authorization manually

Is there a way to also automate that step?

Upvotes: 1

Views: 1423

Answers (2)

JMA
JMA

Reputation: 813

Currently there is no way to connect to external repositories using the API, but there is an ongoing feature request for this to be implemented.

There are two options you can adopt now:

  1. Connect all the repositories at once from the Cloud Console. This way, you will be able to automate the creation of triggers for those repositories.

  2. Use Cloud Source Repositories, which are connected to Cloud Build by default, as indicated here. Check this documentation on how to create a remote repository in CSR from a local git repository.

Upvotes: 2

Vicente Ayala
Vicente Ayala

Reputation: 301

If you use another hosted Git provider, such as on GitHub or Bitbucket, and still need to mirror the repository into Cloud Source Repositories, you must have the cloudbuilds.builds.create permission for the Google Cloud project with which you're working. This permission is typically granted through the cloudbuild.builds.editor role.

Here are some links to this information. Creating and managing build trigger

Upvotes: 0

Related Questions