Installing private dependencies via npm in a VS Te

2019-03-05 02:07发布

I'm setting up some CI builds of NodeJS projects in VS Team Services. I currently have four projects being cloned from private Github repositories, running npm install, and running unit tests. Because I'm giving the VS Team Services build an access token for the repositories it's cloning, these builds all pass.

The fifth project relies on one of the other four projects as a dependency in package.json. The build for this project fails on npm install when attempting to clone the private repository because the build does not have permission to clone the repository. How can I give this build access to clone our private repositories during npm install?

I have one build definition for each of the five projects, and each project is a separate repository in my-org on Github. In each build definition, the connection to Github is managed by personal access token, and the repository points to my-org/project-name. The package.json file of the project in the fifth, failing, build has a dependencies configuration that looks like this:

  "dependencies": {
    "project-name": "git+ssh://git@github.com/my-org/project-name.git#master",
    "jquery": "^2.2.4",
    "react": "^15.0.1",
    "react-dom": "^15.0.1"
  }

The first image shows the npm install step of my build definition. npm install build step

The second image shows the npm test step of my build definition. npm test build step

1条回答
对你真心纯属浪费
2楼-- · 2019-03-05 02:31

The problem is that the build agent will not able to authenticate because of lack of SSH keys on the build agent and because the host verification will fail anyway.

Instead you should create a Personal Access Token on GitHub with 'repo' only scope, then you should use it on your packages.json file (notice that ssh is replaced with https protocol):

"project-name": "git+https://<user>:<token>@github.com/my-org/project-name.git#master",
查看更多
登录 后发表回答