'newman' is not recognized as an internal or external command - node.js

I have followed the following Medium post on How to Configure postman / newman API tests in Azure DevOps or TFS and Publish HTML Results?
In my pipeline I have a task to install newman (Pass with command install newman -g) and a task to run api tests.(Fail - Error: 'newman' is not recognized as an internal or external command.)
I have tried: A few solutions that can be found here and here .
In my Environment variables I have:
npm\node_modules\newman\bin
\npm\node_modules\newman
%AppData%\npm
I did install newman using npm install -g newman and if I run newman -v I get a result of 5.2.2.
My Azure task to run API request: newman run Auth.postman_collection.json -e UserAuthEnvironmentVariables.postman_environment.json --reporters cli,junit --reporter-junit-export Results\junitReport.xml
'C:\Users<user>\AppData\Roaming\npm' contains 3 newman files and C:\Users\RRQA.RRIOMQAS01\AppData\Roaming\npm\node_modules\newman also contains files and folders.
My node version is v14.16.1 and npm version is 6.14.12
When I edit environment variables I do restart my the server to make sure changes did take affect.
Any other suggestions what I might try to figure out the issue.?

When you are running command line from azure and when you locally login to the system it might be running under different user identities (one in admin and another in your account) so sometimes what ever you have installed or set in environment variable won't be available in the admin identity login.
Make sure the installation is done for all users. (Add path to system variable ) else:
install it as local module in the project directory as :
npm install newman newman-reporter-htmlextra
and use :
"./node_modules/.bin/newman" run

Related

Laradock - add custom npm package

It's a kind of not normal thing, but this is something, that temporarily is a solution.
I have laradock installed in a system and laravel app.
All that I'm using from laradock provides me command below
docker-compose up -d nginx mysql php-worker workspace redis
I need to add node package (https://www.npmjs.com/package/tiktok-scraper) installed globally in my docker, so I can get results by executing php code like below
exec('tiktok-scraper user username-n 3 -t json');
This needs to be available for php-fpm and php-worker level, as I need this in jobs and for endpoints, that should invoke scrape.
I know, that I'm doing wrong, but I have tried to install it within workspace like using
docker-compose exec workspace bash
npm i -g tiktok-scraper
and after this it's available in my workspace (I can run for instance tiktok-scraper --help) and it will show me the different options.
But this doesn't solve the issue, as I'm getting nothing by exec('tiktok-scraper user username-n 3 -t json'); in my laravel app.
I'm not so familiar with docker and not sure, in which dockerfile should I put something like
RUN npm i -g tiktok-scraper
Any help will be appreciated
Thanks
To execute the npm package from inside your php-worker you would need to install it in the php-worker container. But for the php exec() to have an effect on your workspace this workspace would need to be in the same container as your php-worker.

Unable to install botskills command

Unable to install npm botskills command on Self-Hosted Azure agent.
Used following command to install packages get updated but when tried to check using "botskills" command it throws up and error saying botskills not available.
Screenshots
Used " npm install -g botskills#latest " to install the package where the following screenshot infers that the botskill packages have been updated.
But when tried to use the updated package it does not work
All the other supporting packages have been updated.
This issue occurs while using the Self-Hosted agent (Windows agent) only and works with no issue on local.
Steps to reproduce
1) Use any of the Microsoft Self-Hosted Agent.
2) Try installing botkskills using following command npm install -g botskills#latest
(Follow the attached screenshots)
3) Try using botskills to verify if the package is available.
I'm not sure if it is supported on a Azure agent, but this looks like a pathing issue.
On a typical machine, in powershell you can run the following to check what your path variable is set to:
$env:path.split(";")
You should typically have something like:
C:\Users\<username>\AppData\Roaming\npm as one of the paths.
For me, bot skills is at:
C:\Users\<myusername>\AppData\Roaming\npm\botskills.ps1
If you don't have that npm path in your path variable, that needs to be remedied somehow. If it's there, then you need to verify that botskills.ps1 is there.
When everything is setup correctly, you can use the following in PowerShell to find the path:
get-command botskills | select path
The error botskills not recognized is because the botskills package installation path is not in the System Environment variables PATH of you local machine. Azure pipeline agent is running as a different user (by default the NetworkService user), and the botskills package is installed by azure pipeline in a different path that unknown to system environment path.
You need to manually add the "path" to the system environment Path for the self-hosted agent machine.
You can also use --prefix to specify a custom npm package installation folder, and make sure add the path to system environment path for the self-hosted agent machine.
npm install botskills#latest -g --prefix C:\custompath\npm
Or you can add the installation path to Environment path in the powershell task using below script.
$env:Path += ";C:\path to botskills installation\npm"
Please check the answer to this thread for more information and the discussion for a similar issue here.

How to run npm command on azure app service after deployment success by VSTS?

Now I can deploy from VSTS to azure, but I can't run npm after deploy is successful.
Now it is work like -> run npm install for branch files => zip => copy to azure => deploy.
I want to add npm run custom-comand to end of this chain.
How to do it?
The Azure App Service Deployment task in VSTS now supports a post-deployment script. Here is a screen-shot from version 3.* of the task:
See Task Parameters for more details.
Windows App Services users: Watch out for an npm bug that prevents multiple npm commands from being run (inline or in a script). For example:
npm install
npm test
Will only run npm install. There are several workarounds including this:
npm install & npm test
There is no out of box build task to achieve the feature you want. If you do want to run the npm from Azure App Service:
Manually: You can go to Kudu console of the App Service and run npm command there:
Automatically: You need to create your own build task to run the npm command via Kudu Rest API
You can run commands like npm install via the Kudu REST API.
Here's a scripted example written in PowerShell.
Add a PowerShell script task after the Azure App Service Deploy task to invoke npm install (or any other command that Kudu supports). And disable the npm install task in your build pipeline.
The Kudu deployment engine that App Service leverages has the ability to run custom deployment scripts. You can include your desired npm command inside of a custom deployment script that will be executed as part of the deployment on Azure's side. No REST API calls required and everything stays in your source control system.
You can use PowerShell task or npm task to execute npm commands .
One thing to note: you also need to upload the .npmrc with auth token to Azure.

Jenkins cannot run npm or pm2 by itself

So I have a Jenkins CI setup on an EC2 server. I have nodejs and npm installed. Weirdly, Jenkins can access them via the command line if I do something like:
sudo -u jenkins node -v
However, Jenkins cannot access them inside an actual build runtime, and I get the following errors:
npm: command not found
pm2: command not found
npm is definitely installed, and ec2-user/root users can access it. What PATH do I have to change so that Jenkins can access it too?
I think that if you use the nodejs plugin it will be easier to manage your node and npm in this box. Also, this plugin allows installing some global modules that possibly you will need to build your project:
https://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin

The term 'gulp' is not recognized as the name of a cmdlet error

So I am trying to run gulp on our build server but keep getting the error above. Everything works fine if I log into the build server with my user account as I installed gulp globally under my account however when Jenkins runs my powershell script it fails with the error:
The term 'gulp' is not recognized as the name of a cmdlet error
So I tried to install globally in my script so that it installs with whatever user Jenkins uses.
Then I added npm -g ls to The powershell script and found that it is installed globally under a system user:
C:\Windows\system32\config\systemprofile\AppData\Roaming\npm >
gulp#3.9.0
Since I am still getting the error I took the advice from this post and added a path variable with the directory above however still the same error.
Anyone have ideas on what I can try next? Im stumped as to why it is not working.
Make sure the directory containing gulp.exe is contained in the $env:PATH environment variable. You can update the machine-wide PATH variable with the [Environment]::SetEnvironmentVariable() method.
Let's imagine the path to the gulp executable is C:\Program Files\gulp\bin\gulp.exe
# Directory containing exe
$GulpFolderPath = 'C:\program files\gulp\bin'
# Retrieve user-agnostic PATH environment variable value
$CurrentEnvPath = [Environment]::GetEnvironmentVariable('PATH','Machine')
# Check if PATH already contains gulp
if($CurrentEnvPath -split ';' -notcontains $GulpFolderPath)
{
# if not, update it
$NewEnvPath = $CurrentEnvPath,$GulpFolderPath -join ';'
[Environment]::SetEnvironmentVariable('PATH',$NewEnvPath,'Machine')
}
Finally a true GULP solution
After having searched for a solution the past two days without success, a colleague assisted me by running the following commands, the first installs gulp locally and globally and the second which I attribute the success for gulp finally running, installs the angular cli globally:
npm i -g gulp gulp
npm i #angular/cli -g
Afterwards I ran this command to update npm packages globally and locally; gulp finally worked:
npm install -g npm
Now running gulp -v yields success:
CLI version: 2.2.0
Local version: 4.0.2
NB: My OS is Windows 10 64 bit architecture latest updates on the 17th of July 2019. No proxy settings, no network ristrictions!!
If you do have a proxy before the internet configure your .npmrc file found by running the command npm config edit from your command line application:
proxy=x.x.x.x:PORT/
https-proxy=x.x.x.x:PORT/
prefix=C:\npm\node_modules
cache=C:\npm\cache

Resources