6

I am trying to install an NPM module from a private Bitbucket repository.

I can successfully run npm install locally on my system, but it fails on the server.

The error is:

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

The strange thing is, cloning the repo on the server manually works fine: git clone git@bitbucket.org:myorg/my-repo

So the SSH keys are configured correctly.

Ozzy Walsh
  • 877
  • 9
  • 17

2 Answers2

2

That should indicate the npm command is not executed with the same account as the one used to manually clone the repo on the server.

In that npm account, the ~/.known_hosts would need to be updated first.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

I think you are accessing it from a Docker container, as you don't have ssh key added from docker container that problem exists. So there are two solutions for this

  1. Make your Git repository public which is not recommended

  2. npm install all the node modules on jenkins and then copy all the node modules to docker container. (Basically instead of npm installing on Docker container from package.json, do it on Jenkins and then copy those modules to container directly

The changes in docker file will be

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"]

And in shell script of Jenkins [in configure] add

npm install

That's it, it should work