Google Cloud Build: Clone Private Repository on google Cloud Repository failing

1k Views Asked by At

We are testing Google Cloud Repositories with Google Cloud Build.

We created a basic cloudbuild.yaml and the build itself is started (we are using Go).

Our Go Programm has some imports that are in the same repository (which is hosted on Google Cloud Repositories) e.g:

  • src/repository
    • main.go (has import source.developers.com/repository/subpackage)
    • subpackage/

in the package itself we have the import path over source.developers.google.com. When Go attempts to clone the repository (when running go get, it fails due to missing credentials:

Step #0: Cloning into '/workspace/gopath/src/source.developers.google.com/ourrepository'...
Step #0: fatal: could not read Username for
'https://source.developers.google.com': terminal prompts disabled
Step #0: package source.developers.google.com/subpackage: exit status 128 [...]

ERROR: build step 0 "gcr.io/cloud-builders/go" failed: exit status 1

The cloud build account already has access to the repository and is allowed to clone it.

How can we clone the repository with Google Build?

2

There are 2 best solutions below

0
On

I think you need to make a docker container that has git in it(ubuntu container) and in that container you clone your repository using ssh keys, after you have linked your container with code repository. Then you push that conyainer onto gcr in your project. Next, in your cloudbuild.yaml you use that very container you pushed, to clone the repo via ssh url.

0
On

Just go to Cloud source repository and select "clone" at the top right, then pick an authentication method, the easiest is "Google cloud SDK" the copy the command and run it in yout command line enter image description here