gpt4 book ai didi

git - 从CloudBuild访问GitHub存储库

转载 作者:行者123 更新时间:2023-12-02 14:26:33 25 4
gpt4 key购买 nike

我正在将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文件读取的。
我究竟做错了什么?

最佳答案

首先,优良作法是:

  • 将您的主机条目命名为githubgh,而不是github.com,以确保使用配置文件(因为ght不能由任何DNS解析,而github.com可以)
  • 在配置文件中也包括User git:这样,要使用的SSH URL变为:'gh':
    ssh -Tvv gh

  • 其次,如果SSH仅读取 /etc/ssh/ssh_config而不是 ~/.ssh/config,则意味着该脚本以某种方式作为 root而不是作为用户启动。

    关于git - 从CloudBuild访问GitHub存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63708412/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com