Azure Pipeline 中的 Azure Artifacts npm 注册表和身份验证

问题描述 投票:0回答:1

我的应用程序中存在身份验证问题。我使用 dotnetpublish 在我的 Azure Pipeline 中构建它,并在其中运行 npm install。我已经配置了 .npmrc 文件,因为我使用两个注册表(一个是 npm,另一个来自 Azure Artifacts)。我仍然收到 401 unauthenticate。

如何使用 PAT 向我的注册表进行身份验证? PAT 设置正确。

@first_registry:registry=https://myregistry/:_authToken=${token} always-auth=true
不工作

.net npm azure-devops azure-pipelines npm-install
1个回答
0
投票

对于管道进行身份验证,建议使用 npm 身份验证任务 而不是使用 PAT。

对于管道身份验证,Azure Artifacts 建议 使用 npm 验证任务。当使用像 gulp 或这样的任务运行程序时 Grunt,将 npm 验证任务添加到 您的管道的开始。这样,您的凭据就会被注入 到项目的 .npmrc 文件中并在管道运行期间保留, 启用后续步骤以使用配置中的凭据 文件。

因此,请尝试在管道的开头添加 npm 验证任务(至少在

npm install
dotnet publish
步骤之前。)

- task: npmAuthenticate@0
  inputs:
    workingFile: .npmrc                ## Path to the npmrc file
    customEndpoint: #Optional          ## Comma-separated list of npm service connection names for registries from external organizations. For registries in your org, leave this blank

请注意,要授予管道对 Feed 的访问权限,请确保在 Feed 设置中将

build service
角色设置为
Contributor

详情请参阅管道认证

© www.soinside.com 2019 - 2024. All rights reserved.