why is azure build pipeline not generating a dist folder for an angular build

Viewed 2075

It seem like the folder that are getting generated during the build are getting deleted before I could ran any other task dist folder.

 trigger:
    - master
    
    pool: default
    
    steps:
    - task: NodeTool@0
      inputs:
        versionSpec: '10.x'
      displayName: 'Install Node.js'
    
    - script: |
        npm install -g @angular/cli
        npm install
        ng build --prod 
      displayName: 'npm install and build'
    
    #i added this task and it seems like the node_modules and the dist 
    #folder that was generated during the build are not getting copied to the (a)directory 
    #only the source code get copied. it seems like the folders are getting
    #deleted even before the #PublishPipelineArtifact@1 task ran
    
    - task: PublishPipelineArtifact@1
      inputs:
        targetPath: '$(Pipeline.Workspace)/s'
        publishLocation: 'pipeline'

I also trying outputting the build in the

2 Answers

Firstly separate npm install script with ng build script. Secondly, I was running npm build instead of ng build. It took me a few hours to notice. This resolved my dist folder not being created issue.

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

- script: |
    ng build --prod
  displayName: 'ng build'

I had the Same issue where i failed to locate the dist folder, but it seemed i was only missing ./ in front of dist on CopyFiles@2 task.

Below is a working build pipeline for a dev/main branch of a angular application.

trigger:
- main
- dev

pool:
  vmImage: ubuntu-latest

jobs:
  - job: 'Dev_build'
    condition: and(succeeded(), eq(variables['build.sourceBranch'], 'refs/heads/dev'))
    steps:
    - task: NodeTool@0
      inputs:
        versionSpec: '16.x'
      displayName: 'Install Node.js'

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

  # Used to diagnostic the file structure
  #  - task: Bash@3
  #    inputs:
  #      targetType: 'inline'
  #      script: 'find -name node_modules -prune -o -print'
  
    - task: CopyFiles@2
      inputs:
        SourceFolder: './dist'
        Contents: '**'
        TargetFolder: '$(build.artifactstagingdirectory)'

    - task: PublishBuildArtifacts@1
      displayName: 'Publish Artifact'
      inputs:
        PathtoPublish: '$(build.artifactstagingdirectory)'
        ArtifactName: 'www'


  - job: 'Prod_build'
    condition: and(succeeded(), eq(variables['build.sourceBranch'], 'refs/heads/main'))
    steps:
    - task: NodeTool@0
      inputs:
        versionSpec: '16.x'
      displayName: 'Install Node.js'

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

    - task: CopyFiles@2
      inputs:
        SourceFolder: './dist'
        Contents: '**'
        TargetFolder: '$(build.artifactstagingdirectory)'

    - task: PublishBuildArtifacts@1
      displayName: 'Publish Artifact'
      inputs:
        PathtoPublish: '$(build.artifactstagingdirectory)'
        ArtifactName: 'www'
Related