12

I have repo in git and trying to build with yaml in vsts. In repository there is only newly created angular project without any changes. When trying to run pipeline with default angular yaml i get following error when running "ng build --prod"

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

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'


# Publish Artifacts
- task: PublishBuildArtifacts@1
  inputs:
    artifactName: dist
    pathtoPublish: 'dist'
Łukasz Misztal
  • 351
  • 1
  • 2
  • 6

3 Answers3

23

OK I found the answer. I needed to add:

workingDirectory: '$(Build.SourcesDirectory)/projectFolderName'

below:

displayName: 'npm install and build'
Luis Gouveia
  • 8,334
  • 9
  • 46
  • 68
Łukasz Misztal
  • 351
  • 1
  • 2
  • 6
1

You would need a file package.json at the specified location under

workingDirectory: '$(Build.SourcesDirectory)/<path_to_file_packages.json>'

The json file could be consisting of

{
     "scripts":{
          "build":"node node_modules/@microsoft/azure-data-factory-utilities/lib/index"
     },
     "dependencies":{
          "@microsoft/azure-data-factory-utilities":"^0.1.6"
     }
} 

The latest version of Azure Data Factory Utilities should match the version number here https://www.npmjs.com/package/@microsoft/azure-data-factory-utilities

0
    # Node.js with React
    # Build a Node.js project that uses React.
    # Add steps that analyze code, save build artifacts, deploy, and more:
    # https://docs.microsoft.com/azure/devops/pipelines/languages/javascript
    
    trigger:
    - main
    
    pool:
      vmImage: ubuntu-latest
    
    steps:
    
    
    - task: NodeTool@0
      inputs:
        versionSpec: '10.x'
      displayName: 'Install Node.js'
    
    - task: Npm@1
      inputs:
        command: 'custom'
        workingDir: '$(Build.SourcesDirectory)/Website/ccus_ui'
        customCommand: 'run test'
      continueOnError: true
    
    - script: |
    npm install -g @angular/cli
    npm install
    ng build --prod
  displayName: 'npm install and build'


# Publish Artifacts
- task: PublishBuildArtifacts@1
  inputs:
    artifactName: dist
    pathtoPublish: 'dist'
Shrinand
  • 351
  • 3
  • 5
  • If you add the 'task: Npm@1' section from the code above in your .yml file, the error should go away. Where /Website/ccus_ui is the path to the package.json file – Shrinand Jun 22 '23 at 22:01