目标
您好,我正在创建一个 Node.js 应用程序,以便在自动推送时更新我的代码。
问题
除了实际的 git pull 之外,一切都在其中工作。 repo 是私有(private)的,需要使用 ssh,但是当我在终端中使用相同的命令时它可以工作。我有钥匙串(keychain),所以它不需要我的密码。任何想法以及如何解决这个问题?
相关代码
const exec = require("child_process").exec;
exec('cd ' + repo + ' && git pull origin deployment', (egitpull,stdoutgitpull,stderrgitpull)=>{
if(egitpull) return console.error(`git pull exec error:${egitpull}`)
console.log(`git pull stdout: ${stdoutgitpull}`);
console.log(`git pull stderr: ${stderrgitpull}`);
命令运行:
cd /mp/ && git pull origin deployment
出子进程vrs。在子进程中

编辑:
完全从 key 中删除密码似乎确实解决了这个问题,但出于安全原因,我更希望将它放在那里。
最佳答案
如果您使用 ssh-agent 作为 ssh key ,请尝试转发 SSH_AUTH_SOCK
和 SSH_AGENT_PID
子进程的 env 变量,如下所示:
exec('cd ' + repo + ' && git pull origin deployment',
{
env: {
SSH_AUTH_SOCK: process.env.SSH_AUTH_SOCK,
SSH_AGENT_PID: process.env.SSH_AGENT_PID
}
},
(egitpull,stdoutgitpull,stderrgitpull) => {
// ...
});
关于Node.js 子进程未能通过 GitHub ssh 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54565635/