Fail TeamCity build when angular-cli reports errors - npm

I'm trying to configure team city to run angular 5 application build.
I have powershell step with this script (it's in the build step definition not separate file). npm run build runs ng build
npm install
npm run build
For some reason even if ng build fails team city build won't fail. Status code from npm run is not propagated back to powershell.
See below screen:

TeamCity Fails the build if got a status code != 0 or when got stderr.
You should add Failure Conditions for verifying that the log has an error.
Edit Configuration Settings -> Failure Conditions -> Add failure condition
Select Fail build on specific text in build log
Secelt options Contains and exact text. Set "npm ERR"
in Failure message write "Error was found in build log"
save
Now your build will be FAILED if build log contains this text.
Also, check an error message is logged by build runner

Related

NPM execution problem "Couldn't find a debug log in the cache or working directory" in Azure pipeline

When I tried to execute
NPM with command npx cypress run
it's displaying following error
2022-08-12T07:37:38.5420694Z ##[warning]Couldn't find a debug log in the cache or working directory
2022-08-12T07:37:38.5433010Z ##[error]Error: Npm failed with return code: 1
so can anyone please help me with how I can solve this problem
thank you
Based on your description and screenshot, it is shown that the main error message in the screenshot is "Unknown command: "npx" ". It means that the issue will occur when using "npm install" this task to run your pipeline, it is suggested that try using "Command Line" task and adding "npx" in "Script" to test again.

Change Task Runner Explorer command

In Visual Studio 2019 I have installed the extension call NPM Task Runner.
When I run a the build command the output is:
cmd.exe /c npm run build --color=always
How do I change that to:
npm run build --color=always
Because when I run the first one I get an error.
How can I fix the error or change the command.
P.S.: When I run the command like this npm run build --color=always in the console it works.
This fixed the problem for me.
Tools > Options > Projects and Solutions > Web Package Management >
External Web Tools
Move the $(PATH) entry to the 2nd position in the list by using the
up arrow button.
Post: Executes wrong version of nodejs

NPM - how to publish only if tests pass?

I have tests setup for a package I maintain - create-new-app. When I run npm publish, I want the tests to run first and only if they pass, move on to the publish portion. I thought this is what prepublishOnly was for. My prepublishOnly value looks like this:
prepublishOnly: "npm run test"
That successfully runs the tests prior to publishing, but if the tests fail, it still publishes! How can I get the publish to happen only when tests pass?
it's possible that your npm run test command is not returning a proper error code of non-zero

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

I want to create a VSTS build with npm package auditing capabilities using npm audit. I added a few tasks to run npm audit. The command runs and I can see the details in the console/logs for all the packages. However, the task fails complaining about not finding a logs file. Any idea on how I can get the builds to stop working if I find a high vulnerability package?
EDIT
This is the final line in the result when I run npm audit locally
Notice how it displays vulnerabilities in categories. I want the build to not proceed if there is a non-zero value for High vulnerability.
I got the same error, but then realize that I am using incorrect custom command for npm task:
it was "npm install gulp -g", but should be "install gulp -g" (without npm).
For me it helps.
There isn’t the way to stop/fail build directly if there is a non-zero value for High vulnerability.
The workaround is that you can do it through PowerShell with Build log REST api to analysis whether there is related information in the log, then fail the build (Write-error …) (Run the powershell through PowerShell task)

running bower from TeamCity (Windows)

I've got a set of build steps in a project (Team City 9.0c)
One of them is running bower install which is a simple command line execution with no parameters.
Bower is installed on the system (I can run it just fine from the command prompt on the machine) but I get the following error
[10:47:35][Step 2/7] Starting: D:\TeamCity\buildAgent\temp\agentTmp\custom_script8385462966123630321.cmd
[10:47:35][Step 2/7] in directory: D:\TeamCity\buildAgent\work\5d43cd6017ab83d4\website\Amaze.Web
[10:47:37][Step 2/7] 'bower' is not recognized as an internal or external command,
[10:47:37][Step 2/7] operable program or batch file.
[10:47:37][Step 2/7] Process exited with code 1
[10:47:37][Step 2/7] Step Bower (Command Line) failed
I've seen this before where PATH is not set to the location of the npm binaries in c:\users\xxxx\roaming\... so the TC user cannot find them, however PATH is correct.
Both npm and grunt work successfully. What could be causing this?
Is the path variable defined a user variable? If so, it should be a system variable which will be used by the TeamCity process.
You haven't written which accounts the build agent runs as.
I had a similar problem and my build agent was running using Local System. I had to create a dedicated windows user account for the teamcity build agent, in the build script I added
npm install -g bower
set path=%path%;c:\path_to_bower_for_this_user;