Azure DevOps 管道中的 npm 身份验证失败

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

我遵循了有关将 Angular 应用程序部署到 ADO 管道的官方教程,这是我的 yaml。

# Node.js with Angular

# Build a Node.js project that uses Angular.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript

trigger:
- main

pool:
  vmImage: ubuntu-latest

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '18.x'
  displayName: 'Install Node.js'

- task: npmAuthenticate@0
  inputs:
    workingFile: '.npmrc'
- script: |
    npm install -g @angular/cli
    npm install
    ng build --prod
  displayName: 'npm install and build'

但是管道在 npm install 时失败,并出现以下错误:

npm ERR! code E401 
npm ERR! Unable to authenticate, your authentication token seems to be invalid.

应用程序正在本地运行,但在管道中失败。对于上下文,该应用程序使用来自外部组织提要的库,并在本地将我的凭据放入用户目录中的 .npmrc 中,并将注册表放在项目目录中的 .npmrc 中。

我尝试将 .npmrc 与存储库根目录中使用的注册表一起放置,我还尝试使用我的用户 .npmrc 并将其保存在变量中,然后将其回显到 yaml 文件中的 .npmrc 但没有以上帮助我解决了问题。

angular npm azure-pipelines npm-install azure-pipelines-build-task
1个回答
0
投票

运行之前需要进行身份验证

npm install

确保在此之前在您的管道中添加此步骤。

Azure Artifacts 凭据提供程序:

此提供程序是手动处理

.npmrc
文件的更好替代方案。

- script: |

npm install -g vsts-npm-auth
vsts-npm-auth -config .npmrc
displayName: 'Authenticate npm'

我过去遇到过的其他需要仔细检查的小事情:

确保根目录中的

.npmrc
文件使用正确的语法正确引用提要 URL。

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