【问题标题】:Error installing a package published to Azure DevOps NPM Artifacts in other organization project在其他组织项目中安装发布到 Azure DevOps NPM Artifacts 的包时出错
【发布时间】:2020-09-25 11:34:35
【问题描述】:

我正在为我的组织使用 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/&lt;MyOrganization&gt;/&lt;My-Library-Project&gt;/_packaging/&lt;My-Library-Project-Artifact-Feed&gt;/npm/registry/@&lt;myorganization&gt;/&lt;my-library-package-name&gt;/-/&lt;my-library-package-name&gt;-0.0.6.tgz--- 的 url,浏览器会下载我的包! p>

总结一下:

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

但还是失败了。

有什么我可以尝试的建议吗?

谢谢!!

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

【问题讨论】:

    标签: npm azure-devops azure-pipelines npm-install npm-publish


    【解决方案1】:

    从位于同一组织但在不同项目中的 Azure DevOps 管道连接到私有项目范围的源时,该源的范围必须允许访问其他项目的生成服务。无论提要的范围如何,构建服务也必须单独添加到提要权限中。

    这是project scoped feed 权限的问题。简而言之,要访问与运行管道的项目不同的项目范围的项目范围提要,运行管道的项目必须能够访问提要范围的项目和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]) 至少为协作者访问权限,以便可以从上游源提取包。如果您只授予读取权限,则无法从上游源提取包。

    【讨论】:

    • 你真是个冷酷的天才!这解决了问题。
    猜你喜欢
    • 1970-01-01
    • 2020-01-30
    • 2022-10-05
    • 2019-04-21
    • 2020-08-23
    • 2018-04-18
    • 2019-03-10
    • 2021-05-18
    • 2023-01-29
    相关资源
    最近更新 更多