Tim*_*Tim 8 authentication npm azure-devops
我有一个应用程序,正在为 Azure DevOps 创建构建管道。它使用私有 npm 注册表中的 npm 包(包含从不同的 Azure DevOps 组织创建的代码)。当我运行npm ci(或npm install)时,它失败并出现以下错误:
npm 错误!代码E401
npm 错误!无法进行身份验证,需要:承载授权_uri = https://login.windows.net/b2d01466-6e2c-4b55-8b90-e3ed41afca4a,基本领域 =“https://pkgsproduks1.pkgs.visualstudio.com/”,TFS-Federated
失败的特定包是来自其他组织的包,401当尝试获取它们时会返回 a 。
我认为验证这一点的最佳实践是在 Azure DevOps 中创建服务连接。我在托管 npm 包的组织内创建了一个个人访问令牌,并使用它在包含我的构建管道的组织中创建了一个服务连接。然后我将其包含在我的构建管道 yaml 中,如下所示:
- task: Npm@1
displayName: Install npm packages
inputs:
command: 'ci'
workingDir: 'Path/To/Working/Directory'
customEndpoint: 'Custom npm registry'
Run Code Online (Sandbox Code Playgroud)
我还尝试过npm authenticate在此之前使用构建步骤(无论有没有customEndpoint: 'Custom npm registry'安装步骤),虽然npm authenticate运行成功,但对我收到的错误没有任何影响。我还尝试将服务连接设置为使用我的用户名和密码而不是 PAT,但这也没有什么区别。
我的项目中的内容.npmrc如下(略有修改):
registry=https://registry.npmjs.org/
@{scope}:registry=https://pkgs.dev.azure.com/{organisation}/_packaging/{feedName}/npm/registry/
@{scope}:always-auth=true
Run Code Online (Sandbox Code Playgroud)
任何人都可以看到身份验证有什么问题,或者链接到提供跨多个 Azure DevOps 组织执行此操作的示例的文章吗?
应该.npmrc看起来像:
registry=https://pkgs.dev.azure.com/{organization}/{project}/_packaging/{feed}/npm/registry/
@{scope}:registry=https://pkgs.dev.azure.com/{otherorganization}/_packaging/{feed}/npm/registry/
@{otherscope}:registry=https://{thirdPartyRepository}/npm/registry/
always-auth=true
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15288 次 |
| 最近记录: |