Azure管道中的npm注册表和身份验证

l7wslrjt  于 6个月前  发布在  其他
关注(0)|答案(1)|浏览(75)

我在我的应用程序中遇到身份验证问题。我使用dotnet publish在我的Azure Pipeline中构建它,在那里我运行npm install。我已经配置了.npmrc文件,因为我使用两个注册表(一个npm,另一个来自Azure Artifacts)。我仍然收到401 unathenticate。
如何使用PAT对注册表进行身份验证?PAT设置正确。@first_registry:registry=https://myregistry/:_authToken=${token} always-auth=true不工作

2exbekwf

2exbekwf1#

对于管道的身份验证,建议使用npm authenticate task而不是PAT。
对于管道的身份验证,Azure Artifacts建议使用npm authenticate task。使用gulp或Grunt等任务运行器时,将npm authenticate任务添加到管道的开头非常重要。通过这样做,您的凭据将注入到项目的.npmrc文件中,并在管道运行期间保持,从而使后续步骤能够使用配置文件中的凭据。
因此,请尝试在管道的开头添加npm authenticate task(至少在npm installdotnet 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

字符串
请注意,要授予您的管道访问您的提要的权限,请确保您在提要设置中将build service角色设置为Contributor
有关详细信息,请参阅Pipeline身份验证。

相关问题