在VS Team Services CI构建中通过npm安装私有依赖项 [英] Installing private dependencies via npm in a VS Team Services CI build

查看:65
本文介绍了在VS Team Services CI构建中通过npm安装私有依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在VS Team Services中设置一些NodeJS项目的CI版本.我目前有四个项目是从私有Github存储库中克隆的,正在运行npm install和正在运行单元测试.因为我要给VS Team Services建立一个正在克隆的存储库的访问令牌,所以这些构建都可以通过.

第五个项目在package.json中依赖于其他四个项目之一.尝试克隆私有存储库时,此项目的构建在npm install上失败,因为该构建没有克隆存储库的权限.如何在npm install期间授予此构建访问权限以克隆我们的私有存储库?

我对五个项目中的每一个都有一个构建定义,并且每个项目在Github上的my-org中都是一个单独的存储库.在每个构建定义中,通过个人访问令牌管理与Github的连接,并且存储库指向my-org/project-name.在第五个失败的项目中,项目的package.json文件具有如下所示的dependencies配置:

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

第一张图显示了我的构建定义的npm install步骤.

第二张图片显示了我的构建定义的npm test步骤.

解决方案

问题是,由于构建代理上缺少SSH密钥,并且主机验证仍然会失败,因此构建代理将无法进行身份验证.

相反,您应该在GitHub上创建一个个人访问令牌,并使用'repo' only 作用域,那么您应该在您的packages.json文件中使用它(请注意,ssh已被https协议替换):

"project-name": "git+https://<user>:<token>@github.com/my-org/project-name.git#master",

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.

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

解决方案

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

这篇关于在VS Team Services CI构建中通过npm安装私有依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆