2
votes

I prepared a powershell script in azure devops build pipeline to create an artifact, but when I start build queue, I get an error which is below.

The build command requires to be run in an Angular project, but a project definition could not be found.

Can someone help me please.

Powershell script:

npm install

npm install -g typescript

npm install -g @angular/cli

ng build --configuration=production

This is all the result of powershell script:

##[section]Starting: PowerShell Script
==============================================================================
Task         : PowerShell
Description  : Run a PowerShell script on Windows, macOS, or Linux.
Version      : 2.148.0
Author       : Microsoft Corporation
Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613736)
==============================================================================
Generating script.
========================== Starting Command Output ===========================
##[command]"C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'd:\a\_temp\90129c3e-4840-41d7-895c-2f9c8f6e5968.ps1'"
npm WARN saveError ENOENT: no such file or directory, open 'D:\a\1\s\package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open 'D:\a\1\s\package.json'
npm WARN s No description
npm WARN s No repository field.
npm WARN s No README data
npm WARN s No license field.

up to date in 5.231s
found 0 vulnerabilities

C:\npm\prefix\tsc -> C:\npm\prefix\node_modules\typescript\bin\tsc
C:\npm\prefix\tsserver -> C:\npm\prefix\node_modules\typescript\bin\tsserver
+ [email protected]
updated 1 package in 2.063s
C:\npm\prefix\ng -> C:\npm\prefix\node_modules\@angular\cli\bin\ng
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\@angular\cli\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

+ @angular/[email protected]
added 295 packages from 180 contributors in 88.373s
The build command requires to be run in an Angular project, but a project definition could not be found.
##[error]PowerShell exited with code '1'.
##[section]Finishing: PowerShell Script
1

1 Answers

2
votes

As the error said, you try to run ng build not in the project folder.

You need to run cd path/to/project-folder before.

Another option, in the Azure DevOps PowerShell task there is a option to specify "Working Directory" so enter there the project path.