1

I have Cloud Build Trigger that runs on a push to a given branch of my GitHub repo.

In my cloudbuild.yaml file I am trying to access one of my private GitHub repos. That doesn’t work. Here's the step that fails:

steps:
...
- name: 'gcr.io/cloud-builders/git'
  id: Clone env repository
  args: 
  - clone
  - --recurse-submodules
  -  git@github.com:my-username/my-service-env

The error from cloud build is:

Already have image (with digest): gcr.io/cloud-builders/git
Cloning into 'my-service-env'...
Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

When I change the git command the error changes as well.

Different command:

steps:
...
- name: 'gcr.io/cloud-builders/git'
  id: Clone env repository
  args: ['clone', 'https://github.com/my-username/my-service-env.git']

New error:

Already have image (with digest): gcr.io/cloud-builders/git
Cloning into 'my-service-env'...
fatal: could not read Username for 'https://github.com': No such device or address

Looking at some docs here, it says if the build was started through a trigger you should be able to access a private repo. That doesn't seem like the case here.

I wanted to know if anyone had any success accessing their private GitHub repo this way before I start configuring SSH keys.

NB: This question is pretty much the same as this one but the answer on that page is not relevant.

Gilbert Nwaiwu
  • 687
  • 2
  • 13
  • 37
  • 1
    Did you add the SSH key to the `known_hosts.github` file? [`ssh-keyscan -t rsa github.com > known_hosts.github`](https://cloud.google.com/build/docs/access-github-from-build#add_the_public_ssh_key_to_known_hosts) – Farid Shumbar Oct 04 '21 at 14:12
  • I had to go through that route eventually. I don't know why the docs say you can access any private repo without doing that because it clearly doesn’t work, at least not in my case – Gilbert Nwaiwu Oct 04 '21 at 14:38
  • So did you manage to access the repo with the SSH key in the file? – Farid Shumbar Oct 04 '21 at 14:41
  • Yes, I did. But even for a trigger that auto pulls a target GitHub repo, I cant push changes. Still have to define the ssh key and then override the remote origin to use ssh instead of https. – Gilbert Nwaiwu Oct 05 '21 at 05:19
  • It looks like there is a [Feature request](https://issuetracker.google.com/issues/150198815) about the same issue. Let me know if it answers your question – Farid Shumbar Oct 12 '21 at 10:58
  • yes i had to just reclone the repo again using ssh to a different directory in order to access the git remote. its a bit limiting cloudbuild doesnt let you do much with the repo it cloned. – developerinlondon Dec 06 '21 at 18:37

0 Answers0