Reputation: 10548
I am using Google CloudBuild as a CI server. It is using a mirror-repo of my GitHub repo to detect/pull changes, which works perfectly fine.
My problem is that once CloudBuild has successfully run all my tests, I want it to add a tag to my repo. I am using the gcr.io/cloud-builders/git
container, but I can't push tags directly since this is only connected to the mirrored repo. So, to get around this, I am using a shell script to clone the repo directly from Github to actually create a tag.
When I try to access Github from Cloudbuild, I get the following error message:
Step #3: debug1: read_passphrase: can't open /dev/tty: No such device or address
Step #3: Host key verification failed.
Step #3: fatal: Could not read from remote repository.
Step #3:
Step #3: Please make sure you have the correct access rights
Step #3: and the repository exists.
Here is the script I am using (it just tests github access):
#!bin/sh
# Copy private key to ~/.ssh directory
cp ./path/to/my/key ~/.ssh/github
chmod 600 ~/.ssh/github
# Create SSH config file
cat >~/.ssh/config <<EOL
Host github.com
HostName github.com
AddKeysToAgent yes
IdentityFile ~/.ssh/github
EOL
chmod 600 ~/.ssh/config
# Add key to agent
eval "$(ssh-agent -s)"
ssh-keyscan github.com >> ~/.ssh/known_hosts
ssh-add -k ~/.ssh/github
# Set GIT config
git config --global user.name "myusername"
git config --global user.email "[email protected]"
# Test authentication with Github
ssh -T [email protected]
Another relevant part of the debug logs is this:
Step #3: debug1: Reading configuration data /etc/ssh/ssh_config
Step #3: debug1: /etc/ssh/ssh_config line 1: Applying options for github.com
It seems to be reading from /etc/ssh/ssh_config
instead of the ~/.ssh/config
file I created.
What am I doing wrong?
Upvotes: 1
Views: 579
Reputation: 1323115
First, it is good practice to:
name your Host entry github
or gh
, not github.com
, in order to be sure to use the config file (since gh cannot be resolved by any DNS, while github.com
can)
include the User git
as well in the config file: that way, the SSH URL to use becomes: 'gh
':
ssh -Tvv gh
Second, if SSH reads only /etc/ssh/ssh_config
instead of ~/.ssh/config
, that means the script is somehow launched as root
, not as the user.
Upvotes: 1