ng build --prod 无法在 Azure CICD 管道中工作

Ron*_*ano 1 azure-devops angular

我正在 Azure 中设置应用程序 CI/CD,但我不明白为什么它在构建过程中仍然失败。

这是我的 yaml

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

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

- script: |
    npm install
  displayName: 'npm install'

- script: |
    npm uninstall -g angular-cli
    npm cache clean or npm cache verify #(if npm > 5)
    npm install -g @angular/cli@7.1.4
  displayName: 'npm install @angular/cli'

- script: |
    ng build --prod
  displayName: 'npm build'
- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: '/src/app/dist/my-app'
    includeRootFolder: true
    archiveType: 'zip'
    archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
    replaceExistingArchive: true
Run Code Online (Sandbox Code Playgroud)

我以为是 CLI,但是按照网上的解决方案仍然失败。

And*_*rei 5

azure CI/CD 未ng安装实用程序。但它知道npm. 只需在 package.json 中添加 npm 脚本来调用ng build --prod它,然后通过 yaml 中的 npm 调用它即可。

//package.json
"scripts": {
  "build:prod": "ng build --prod"
}
....
// yaml
- script: |
  npm run build:prod
Run Code Online (Sandbox Code Playgroud)