- 进口this GitHub 存储库到 Azure 存储库。
- 使用经典编辑器创建了构建管道,其 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
步骤中给出错误:
文本错误:
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 时,我收到了相同的错误代码:-
现在,我使用了下面的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'
输出:-
代码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'
输出:-
关于angular - `npm install` 命令在基本 Angular 应用程序的 azure 构建管道中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76751887/