TFS 2017 on-premise cannot find node modules in cmd - node.js

How to run npm modules in tfs agent running as a service?
Here's my setup.
I setup agent on local machine with TFS 2017 running on-premise.
And I try to build aurelia application on agent running as a service.
I already have installed node, aurelia cli and npm in machine where the agent run. It was globally accessed running manually cmd with command au build(aurelia cli build). However when I create a Command Line build step running au(Tool) and build(Arguments) the agent does not find au.
I think it will also not find other npm modules.

In general, the build agent (running as service) uses Network Service account and the installed npm packages are in current user folder, so you can call au command directly, but can’t call au command during the build.
You can change build agent service account to use your account or refer to these steps to install Aurelia-cli package and call au command in Command Line step if you still uses Network Service account:
Add Command line step to build definition (Tool: npm; Arguments: install Aurelia-cli -g)
Add Command line step (Tool: C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\npm\au; Arguments: build; Working folder: [project folder] (e.g. $(Build.SourcesDirectory))
Note: the step 1 just need to run only once, you can disable or delete it for next build to save time.
On the other hand, you can try to add C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\npm to environment variable (system variables > Path), then use au directly.

Related

electron-winstaller throws The system cannot find the path specified. at Squirrel.Utility.<CreateZipFromDirectory>d__23.MoveNext()<---

I am trying to build a electron installer for windows platform in Azure DevOps. I have successfully ran the electron-package command with npm run build (look at my package.json). After that when I try to run the command to create the RELEASES, .msi, .exe and .nupkg files with electron-winstaller it throws an error saying:
The system cannot find the path specified.
at Squirrel.Utility.d__23.MoveNext()<---
The command that I executed was npm run create-installer-win which executes the command node build.js.
The build runs in a on-premises agent with windows server 2014.
Locally everything works fine.
Image of my build.js
Image of my package.json
enter image description here
The was with Squirrel.
My agent is running with NT AUTHORITY\System user which does not have permission to create the SquirrelTemp folder in %appdata%. When it try to create de folder in current folder it throws the error because it does not find the SquirrelTemp folder.
The solution I have found was to set a environment variable SQUIRREL_TEMP in the build pipeline with the value to %currentfolder%\SquirrelTemp and it works.
Thanks to https://github.com/Squirrel/Squirrel.Windows/issues/1081#issuecomment-340958128

npm command is not found when ssh with bitbucket pipelines on shared hosting

I've installed nodejs as described here.
Everything works fine when I ssh to the server myself. But I've created a script that deploys my application and call it via bitbucket pipelines. Everything else works fine (composer install, php artisan migrate etc.), except npm install. The error message is
./deploy: line 26: npm: command not found
In bitbucket-pipelines.yml I call my script like this:
- step:
script:
- ssh user#ip_address ./deploy
When I call the script by myself everything works. The problem is only with bitbucket pipelines. I have no clue why this happens :(.
Running which composer revealed that at least composer command is not getting picked up from your assumed location i.e., ~/composer dir. Instead, it was found in /opt/cpanel/composer/bin/composer.
which npm returned the following:
no npm in (/usr/local/cpanel/3rdparty/lib/path-bin:/usr/local/jdk/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/usr/local/bin:/usr/X11R6/bin:/root/bin:/opt/bin:/opt/cpanel/composer/bin:/home/handmast/.local/bin:/home/handmast/bin)
Now since you are able to manually run the command npm, you just need to figure about the path from where npm is running and ensure that the path is explicitly added to the user's ~/.bashrc file and things should work fine. You need to do this because as per your observation, ssh is not able to find it.
export PATH=$PATH:/path/to/npm/binary
Note: To avoid any confusion, just remember that while adding the path to your binary, you just have to add the path to the directory where npm resides. Don't add npm at the end. For example, following is incorrect way:
export PATH=$PATH:/home/handmast/bin/npm
Correct way is this:
export PATH=$PATH:/home/handmast/bin

Cannot install Azure Dev Spaces using cloud shell in AKS

When i run the below command in cloud shell.
az aks use-dev-spaces -g aksrgrp -n akscluster
I get the below error. Any help will be highly appreciated
You may be prompted for your administrator password to authorize the installation process.
/tmp/tmpy1vng2we/azds-linux-setup.sh: line 84: sudo: command not found
/tmp/tmpy1vng2we/azds-linux-setup.sh: line 112: sudo: command not found
[INFO] Failed to install dotnet core dependencies.
[INFO] You can manually install all required dependencies based on the following documentation:
[FATAL] https://www.microsoft.com/net/download/dotnet-core/2.1
Azure Dev Spaces CLI not installed properly. Visit 'https://aka.ms/get-azds' for Azure Dev Spaces.
The error shows why the issue happens. It cannot find the command azds. Because the cloud shell does not install the command tool. You can find all the command tools installed in the cloud shell here.
I suggest you can install the tool which you need in the Azure VM of the azure Kubernetes, if you do not find the tool what you want.
It's a better way for you. By the way, the Cloud Shell just enables access to a browser-based command-line experience built with Azure management tasks in mind. So install the Azure CLI in the VM is a better experience.
To add to Charles's answer: the Azure Dev Spaces CLI currently does not support running in the Cloud Shell. Its functionality is designed more for running on your local dev machine where you application's source code is.

Running nodejs command on gocd pipeline

I created a new gocd pipeline and have three shell script files to run on different stages.
The problem is the go agent doesn't know npm.
Note: I have npm installed on the machine with go agent and I manually run the shell script from the pipeline.
Here is my shell script to install the packages.
#!/bin/sh
npm install
The error:
01:34:43.674 [go] Start to execute task: <exec command="./install.sh" />.
01:34:43.680 ./install.sh: line 3: npm: command not found
01:34:43.814 [go] Current job status: failed.
Problem
Assuming you have npm/nodejs installed on the agent, the problem probably lies in the fact the user doesn't have its PATH environment variable configured to look into the folder npm was installed in.
Solution
1) You can specify the whole path (/usr/bin/npm) when creating a task.
2) You can edit the .bashrc/.bash_profile of the user running the gocd agent server. In which case you'll be able to call '/usr/bin/npm' without the path prepended.
Example Working Configuration
Consider modification of the agent init script. Changing .bashrc/.bash_profile of the user running the gocd agent does not work because the go agent insulates itself from the calling environment. So on our systems we add these PATH items to the go agent startup scripts. (I use puppet to create agents. The default agent init scripts are not that good - you need to own them.)

Running Karma from TeamCity

Does anyone know how you would run the following command within TeamCity? (the command is normally ran in a Node.js command window)..."Karma start karma.conf.js". I have successfully installed Nodejs on the TeamCity server. I have then successfully installed Karma on the same server (using npm install -g karma).
In TeamCity, my build step has "Runner type = Command Line", and the Custom Script is set to "FULLPATHOFKARMAEXE\karma.cmd start FULLPATHOFKARMACONFIGFILE/kara.conf.js"
When i run TeamCity, it comes back with the error "node is not recognized as an internal or external command"
Anyone know the step-by step process of running Karma within TeamCity?
In your case, the Karma installation seems to be OK, but your TeamCity agent process is unable to resolve the path to Node.exe (it's installation folder is missing from the %PATH% variable).
First verify the NodeJS installation by opening a Commandline window on the agent machine, type node and press enter:
c:> node
>
If the result in your Command window is a >-prompt, you might solve your problems by restarting the build agent.
If the result in your Command window is some error message saying "node is not recognized as an internal or external command", you need to add the NodeJS installation folder to the %PATH% variable, and restart the build agent.
You can, of course, just change the %PATH% for your build agent service by running a initialization script included in the NodeJS installtion folder in your build step. Depending on where your NodeJS installastion is, your custom script might look like this:
"C:\Program Files (x86)\nodejs\nodevars.bat"
"FULLPATHOFKARMAEXE\karma.cmd start FULLPATHOFKARMACONFIGFILE/kara.conf.js"

Resources