如何解决从CloudBuild访问GitHub存储库
我正在将Google CloudBuild用作CI服务器。它使用我的GitHub存储库的镜像存储库来检测/拉动更改,效果很好。
我的问题是,一旦CloudBuild成功运行了所有测试,我希望它向我的存储库添加标签。我正在使用gcr.io/cloud-builders/git
容器,但是由于它仅连接到镜像存储库,因此无法直接推送标签。因此,为了解决这个问题,我正在使用Shell脚本直接从Github复制存储库以实际创建标签。
当我尝试从Cloudbuild访问Github时,出现以下错误消息:
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.
这是我正在使用的脚本(它只是测试github访问权限):
#!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 "myusername@users.noreply.github.com"
# Test authentication with Github
ssh -T git@github.com
调试日志的另一个相关部分是:
Step #3: debug1: Reading configuration data /etc/ssh/ssh_config
Step #3: debug1: /etc/ssh/ssh_config line 1: Applying options for github.com
它似乎是从/etc/ssh/ssh_config
而不是我创建的~/.ssh/config
文件中读取的。
我在做什么错了?
解决方法
首先,优良作法是:
-
将您的主机条目命名为
option not found
或github
,而不是gh
,以确保使用配置文件(因为gh无法由任何DNS解析,而github.com
可以) -
在配置文件中还包括
github.com
:这样,要使用的SSH URL变为:'User git
':gh
第二,如果SSH仅读取ssh -Tvv gh
而不是/etc/ssh/ssh_config
,则意味着该脚本以某种方式以~/.ssh/config
而不是用户身份启动。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。