Home > OS >  Azure CI/CD pipeline Angular failing
Azure CI/CD pipeline Angular failing

Time:12-22

With a new build I set up I cant seem to get a solid working YAML setup.

I am trying to build an Angular project and publish it as an artifact.

Here is what I have:

- script: |
    npm install -g @angular/cli
    npm install
    npm uninstall @angular-devkit/build-angular
    npm install @angular-devkit/build-angular
    ng build --prod

- task: Npm@1
  displayName: 'Build Angular'
  inputs:
    command: custom
    workingDir: 'Mpw/Mpw.Web.UI/ClientApp'
    verbose: false
    customCommand: 'run build'
    
- task: CopyFiles@2
  displayName: 'Copy dist to artifacts'
  inputs:
    SourceFolder: 'test/test.UI/ClientApp/dist'
    Contents: '**'
    TargetFolder: 'test/test.UI/ClientApp/dist'
    cleanTargetFolder: true

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifacts'
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)/Application'
    ArtifactName: 'test-uat'

But I get the following error output on the pipeline:

2021-12-20T11:55:12.7224058Z [command]C:\Windows\system32\cmd.exe /D /S /C ""C:\Program Files\nodejs\npm.cmd" run build"
2021-12-20T11:55:18.9961043Z Node packages may not be installed. Try installing with 'npm install'.
2021-12-20T11:55:18.9961498Z 
2021-12-20T11:55:18.9962153Z Could not find the '@angular-devkit/build-angular:browser' builder's node package.
2021-12-20T11:55:18.9962748Z > [email protected] build
2021-12-20T11:55:18.9963084Z > ng build
2021-12-20T11:55:18.9963194Z 
2021-12-20T11:55:19.1210342Z ##[warning]Couldn't find a debug log in the cache or working directory
2021-12-20T11:55:19.1215101Z ##[error]Error: Npm failed with return code: 1
2021-12-20T11:55:19.1221947Z ##[section]Finishing: Build Angular

I am not sure if my Yaml is 100% correct

CodePudding user response:

Node packages may not be installed. Try installing with 'npm install'.

  • Update the node and angular cli version
  • Use command npm install npm@latest. And npm install @angular/cli@latest

Couldn't find a debug log in the cache or working directory

Use the below command for npm task "install gulp -g"

Could not find the '@angular-devkit/build-angular:browser' builder's node package.

Install @angular-devkit/build-angular as dev dependency.

npm install --save-dev @angular-devkit/build-angular

or,

yarn add @angular-devkit/build-angular --dev

For upgrade problem

  1. Delete these files/ folders (from your Angular root folder):

    • package-lock.json (Not the package.json)
    • /node_modules folder
    • /dist folder
  2. Execute command (regenerate the package-lock.json and the /node_modules):

    • $npm install

It is the package-lock.json that causes npm to download old versions of dependencies.

CodePudding user response:

I think you are missing node install task.

Follow the installation instructions here: https://docs.microsoft.com/en-us/azure/devops/pipelines/ecosystems/javascript?view=azure-devops&tabs=code

  • Related