从私有Bitbucket安装NPM模块时,主机密钥验证失败

时间:2018-10-18 23:25:14

标签: git npm

我正在尝试从私有Bitbucket存储库中安装NPM模块。

我可以在系统上本地成功运行npm install,但是在服务器上失败。

错误是:

npm ERR! Error while executing:
npm ERR! /bin/git ls-remote -h -t ssh://git@bitbucket.org/myorg/my-repo.git
npm ERR! 
npm ERR! 
npm ERR! (ssh-askpass:10260): Gtk-WARNING **: cannot open display: :0.0
npm ERR! Host key verification failed.
npm ERR! fatal: Could not read from remote repository.
npm ERR! 
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR! 
npm ERR! exited with error code: 128

奇怪的是,在服务器上手动克隆仓库可以正常工作: git clone git@bitbucket.org:myorg/my-repo

因此SSH密钥配置正确。

2 个答案:

答案 0 :(得分:0)

这应该表明npm命令没有与用于在服务器上手动克隆存储库的帐户相同的帐户执行。

在该npm帐户中,the ~/.known_hosts would need to be updated first

答案 1 :(得分:0)

我认为您正在从Docker容器访问它,因为您没有从Docker容器添加ssh密钥,因此存在问题。因此,有两种解决方案

  1. 将您的Git存储库公开,不建议

  2. npm在jenkins上安装所有节点模块,然后复制所有节点模块 到docker容器。 (基本上不是在Docker容器上安装npm 从package.json中,在Jenkins上执行,然后将这些模块复制到容器中 直接

泊坞窗文件中的更改将为

INITIALLY :
FROM node:12.10-alpine
WORKDIR /app
RUN apk update \
  && apk add git
COPY node_modules /app
COPY . /app
ADD set_envs.sh .
RUN ["chmod", "+x", "set_envs.sh"]
EXPOSE 80
ENTRYPOINT ["/app/set_envs.sh"]


AFTER CHANGES :
FROM node:12.10-alpine
WORKDIR /app
COPY node_modules /app
COPY . /app
ADD set_envs.sh .
RUN ["chmod", "+x", "set_envs.sh"]
EXPOSE 80
ENTRYPOINT ["/app/set_envs.sh"]

然后在Jenkins的shell脚本中[在configure中]添加

npm install

就是这样,它应该可以工作

相关问题