angular - `npm install` 命令在基本 Angular 应用程序的 azure 构建管道中失败

标签 angular azure npm azure-pipelines

  1. 进口this GitHub 存储库到 Azure 存储库。
  2. 使用经典编辑器创建了构建管道,其 YAML 代码如下:
trigger:
  branches:
    include:
    - refs/heads/master
jobs:
- job: Job_1
  displayName: Agent job 1
  pool:
    vmImage: ubuntu-latest
  steps:
  - checkout: self
    fetchDepth: 1
  - task: Npm@1
    displayName: npm install
    inputs:
      workingDir: package.json
      verbose: false
  - task: Npm@1
    displayName: npm custom
    inputs:
      command: custom
      workingDir: package.json
      verbose: false
      customCommand: npm run build
  - task: ArchiveFiles@2
    displayName: Archive $(Build.BinariesDirectory)
  - task: PublishBuildArtifacts@1
    displayName: 'Publish Artifact: drop'

不确定,出了什么问题。运行管道时,它在 npm install 步骤中给出错误:

enter image description here

文本错误:

Starting: npm install
==============================================================================
Task         : npm
Description  : Install and publish npm packages, or run an npm command. Supports npmjs.com and authenticated registries like Azure Artifacts.
Version      : 1.221.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/package/npm
==============================================================================
/usr/local/bin/npm --version
9.5.1
##[error]Error: ENOTDIR: not a directory, stat '/home/vsts/work/1/s/package.json/.npmrc'

最佳答案

我通过两种方式使它工作,为了让您的 YAML 管道从存储库中读取代码,您需要使用 predefined variables为了从存储库读取文件,您需要在代码中使用 $(System.DefaultWorkingDirectory)

当我刚刚尝试使用 package.json 甚至 $(System.DefaultWorkingDirectory)/package.json 时,我收到了相同的错误代码:-

enter image description here

现在,我使用了下面的Code-1并且它成功运行了,请参阅下面:-

trigger:
- master

pool:
  vmImage: ubuntu-latest


steps:
  - checkout: self
    fetchDepth: 1
  - task: Npm@1
    displayName: npm install
    inputs:
      workingDir: $(System.DefaultWorkingDirectory)
      verbose: false
  - task: ArchiveFiles@2
    displayName: Archive $(Build.BinariesDirectory)
  - task: PublishBuildArtifacts@1
    displayName: 'Publish Artifact: drop'

输出:-

enter image description here

代码2:-

trigger:
- master

pool:
  vmImage: ubuntu-latest

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

- script: |
    npm install -g @angular/cli
    npm install
    ng build 
  displayName: 'npm install and build'

- task: ArchiveFiles@2
  displayName: Archive $(Build.BinariesDirectory)

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: drop'

输出:-

enter image description here

关于angular - `npm install` 命令在基本 Angular 应用程序的 azure 构建管道中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76751887/

相关文章:

java - 如何选择安全消息传递前端和符合 HIPAA 的数据库解决方案?

typescript - 打字 vs @types NPM 作用域

node.js - meteor EPIPE 错误中的 html-pdf

javascript - 将 json 数据获取到数组 angular2 中

css - 如何在primeng中的卡住和解冻列表中设置不同的列样式和宽度

angular - "p-menu"不是已知元素

xml - 通过 JWT token 在 Azure API 管理中进行授权

html - Angular 教程(英雄之旅)未在英雄列表中显示正确的对齐方式

c# - 使用 Oauth 和 full_access_as_user 对 EWS 进行身份验证

react-native - 如何在 native react 中检查设备是否连接到蓝牙?