在其他组织项目中安装发布到 Azure DevOps NPM 工件的包时出错

Error installing a package published to Azure DevOps NPM Artifacts in other organization project

我正在为我的组织使用 Azure DevOps Pipelines 来处理我们的前端 CI 构建。

我创建了两个 Angular 项目:一个库项目和一个使用该库的应用程序项目。在我的 Organization 中,我每个人都有自己的 DevOps Project,每个人都有自己的 Repo . (例如,库 Angular 代码在 My-Org/My-LibraryProjectRepo,并且使用该库的应用程序在 My-Org/My-ApplicationProjectRepo 中.)

我已成功让 DevOps 将该库的包发布到它的 Artifacts。我已经使用 npm install.

从 CLI 为我的应用程序从 Artifacts 成功安装了那个包

当我尝试使用 Azure Pipeline 构建相同的应用程序时,事情开始看起来不错,但随后我收到警告:

...
2020-09-25T01:40:22.9633584Z npm verb npm-session b9c6c5c07bc27d0f
2020-09-25T01:40:22.9634637Z npm info lifecycle @<myorganization>/<my-application-package-name>@0.0.0~preinstall: @<myorganization>/<my-application-package-name>@0.0.0
...
2020-09-25T01:40:22.9652940Z npm http fetch GET 200 https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz 888ms
2020-09-25T01:40:22.9653589Z npm http fetch GET 200 https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz 885ms
...
2020-09-25T01:40:22.9696448Z npm http fetch GET 200 https://registry.npmjs.org/tar/-/tar-6.0.5.tgz 256ms
2020-09-25T01:40:22.9697172Z npm WARN tar ENOENT: no such file or directory, open '/home/vsts/work/1/s/node_modules/.staging/source-map-655ef13e/dist/source-map.js'
2020-09-25T01:40:22.9697948Z npm http fetch GET 200 https://registry.npmjs.org/minizlib/-/minizlib-2.1.2.tgz 254ms
2020-09-25T01:40:22.9698728Z npm WARN tar ENOENT: no such file or directory, open '/home/vsts/work/1/s/node_modules/.staging/@angular/cli-095a8231/commands/build-impl.js'
2020-09-25T01:40:22.9699541Z npm WARN tar ENOENT: no such file or directory, open '/home/vsts/work/1/s/node_modules/.staging/engine.io-client-a00fe2c5/LICENSE'
...

以不愉快的结局结束:

...
2020-09-25T01:40:23.9366311Z npm WARN tar ENOENT: no such file or directory, open '/home/vsts/work/1/s/node_modules/.staging/rxjs-77a83855/LICENSE.txt'
2020-09-25T01:40:23.9367111Z npm WARN tar ENOENT: no such file or directory, open '/home/vsts/work/1/s/node_modules/.staging/rxjs-77a83855/src/LICENSE.txt'
2020-09-25T01:40:23.9367879Z npm verb unlock done using /home/vsts/.npm/_locks/staging-b6ade8de5fa1f467.lock for /home/vsts/work/1/s/node_modules/.staging
2020-09-25T01:40:23.9369511Z npm verb stack Error: 404 Not Found - GET https://pkgs.dev.azure.com/<MyOrganization>/<My-Library-Project>/_packaging/<My-Library-Project-Artifact-Feed>/npm/registry/@<myorganization>/<my-library-package-name>/-/<my-library-package-name>-0.0.6.tgz
...
2020-09-25T01:40:23.9371625Z npm verb statusCode 404
2020-09-25T01:40:23.9372024Z npm verb pkgid @<myorganization>/<my-library-package-name>@0.0.6
2020-09-25T01:40:23.9372260Z npm verb cwd /home/vsts/work/1/s
2020-09-25T01:40:23.9372620Z npm verb Linux 5.4.0-1025-azure
2020-09-25T01:40:23.9373034Z npm verb argv "/opt/hostedtoolcache/node/12.18.4/x64/bin/node" "/opt/hostedtoolcache/node/12.18.4/x64/bin/npm" "install"
2020-09-25T01:40:23.9373392Z npm verb node v12.18.4
2020-09-25T01:40:23.9373573Z npm verb npm  v6.14.6
2020-09-25T01:40:23.9373749Z npm ERR! code E404
2020-09-25T01:40:23.9374536Z npm ERR! 404 Not Found - GET https://pkgs.dev.azure.com/<MyOrganization>/<My-Library-Project>/_packaging/<My-Library-Project-Artifact-Feed>/npm/registry/@<myorganization>/<my-library-package-name>/-/<my-library-package-name>-0.0.6.tgz
2020-09-25T01:40:23.9375074Z npm ERR! 404
2020-09-25T01:40:23.9375516Z npm ERR! 404  '@<myorganization>/<my-library-package-name>@0.0.6' is not in the npm registry.
...

但这是奇怪的部分:如果我在 Pipeline 报告 404---https://pkgs.dev.azure.com/<MyOrganization>/<My-Library-Project>/_packaging/<My-Library-Project-Artifact-Feed>/npm/registry/@<myorganization>/<my-library-package-name>/-/<my-library-package-name>-0.0.6.tgz 的浏览器中单击 url ---浏览器下载我的包!

总结一下:

  1. 当从命令行为我的应用程序项目执行 npm install 时,我能够从库的 DevOps Artifacts 安装包,并且
  2. 当单击应用程序 Pipeline 日志显示失败的 URL 时,浏览器会从库的 Artifacts,但是
  3. 在我的 DevOps Organization 中运行的应用程序 Pipeline 找不到它。

我怀疑存在某种权限或授权问题,但我不确定下一步该怎么做。

我已经尝试了 npmAuthenticate@0 任务,日志确实显示了令人鼓舞的事情,例如:

2020-09-25T01:40:04.2511306Z ##[debug]Got auth token
..
2020-09-25T01:40:04.2540281Z ##[debug]Created webApi client for https://dev.azure.com/<MyOrganization>/; options: {"proxy":null,"allowRetries":true,"maxRetries":5,"ignoreSslError":false}
2020-09-25T01:40:04.2581233Z ##[debug]Getting URI for area ID <some GUID> from https://dev.azure.com/<MyOrganization>/
2020-09-25T01:40:04.3973124Z ##[debug]Found resource area with locationUrl: https://pkgs.dev.azure.com/<MyOrganization>/
2020-09-25T01:40:04.3976465Z ##[debug]Found serviceUri: https://pkgs.dev.azure.com/<MyOrganization>/
2020-09-25T01:40:04.3978178Z ##[debug]Getting credentials for local feeds
2020-09-25T01:40:04.3978962Z SYSTEMVSSCONNECTION exists true
2020-09-25T01:40:04.3979926Z ##[debug]SYSTEMVSSCONNECTION exists true
2020-09-25T01:40:04.4003325Z ##[debug]Got auth token
2020-09-25T01:40:04.4004250Z ##[debug]Agent.ProxyUrl=undefined
2020-09-25T01:40:04.4005572Z ##[debug]Created webApi client for https://pkgs.dev.azure.com/<MyOrganization>/; options: {"proxy":null,"allowRetries":true,"maxRetries":5,"ignoreSslError":false}
2020-09-25T01:40:04.4007252Z ##[debug]Acquiring Packaging endpoints...
2020-09-25T01:40:04.6490830Z ##[debug]Successfully acquired the connection data
2020-09-25T01:40:04.6502681Z ##[debug]Acquired location
2020-09-25T01:40:04.6503915Z ##[debug]{"PackagingUris":["https://dev.azure.com/<MyOrganization>/","https://pkgs.dev.azure.com/<MyOrganization>/","https://pkgsprodcus1.pkgs.visualstudio.com/","https://pkgs.dev.azure.com/<MyOrganization>/","https://<myorganization>.pkgs.visualstudio.com/","https://pkgs.dev.azure.com/<MyOrganization>/"],"DefaultPackagingUri":"https://pkgs.dev.azure.com/<MyOrganization>/"}

还是失败了

关于我可以尝试什么的任何建议?

谢谢!!

P.S。我应该补充一点,我有 很多 可以分享的更多信息,包括我的 package.json.npmrc,以及整个日志,但我想保持简短。如果您需要我分享其他详细信息,请告诉我,我会添加它们。谢谢!

When connecting to a private project scoped feed from an Azure DevOps pipeline that is in the same organization but in a different project, the project that the feed is scoped to must allow access to the other project's build service. The build service must also be separately added to the feed permissions, regardless of the scope of the feed.

这是 project scoped feed 权限的问题。简而言之,要访问一个项目范围内的提要,该提要的范围是与管道 运行 所在的项目不同的项目,管道 运行 所在的项目必须有权访问两个供稿范围内的项目和供稿本身。

以下是设置适当权限的方法。

  1. 检查管道在 运行 中的项目。需要添加到提要权限的构建服务权限和提要的项目权限将类似于 [Project name] Build Service ([Organization name]).

  2. 在提要范围内的项目中,转到 permission settings 将管道的项目构建服务 ([Project name] Build Service ([Organization name])) 添加到贡献者组,或一些您的项目可能拥有的其他组允许贡献者访问其用户。

  3. feed permission 页面中,至少添加 [Project name] Build Service ([Organization name]) 协作者访问权限,以便可以从上游来源获取包。如果您只授予读取权限,则无法从上游来源提取包。