Angular CLI VSO Continuous Integration - continuous-integration

I have set up CI for Angular2 projects in the past which use npm commands, however I recently started using Angular-CLI which uses 'ng' commands instead.
When I try to set up CI for my project in Visual Studio Online I can't find a way to execute 'ng' commands.
I have tried running NPM command (using npm task from the catalog) to install the CLI; npm install -g angular-cli, after that I run npm install. Now to run 'ng build' I have tried to run in using command line tool (since there doesn't appear to be a tool to allow me to run ng commands), however that fails saying that ng is not a recognised command.
Any suggestions on setting up CI for an Angular-CLI project using VSO?
Thanks

If you want your build definition to run on any build agent (the Hosted one and any on premise agent), you could relying on local installation of angular-cli with npm, without the -g flag:
>npm install angular-cli
By default npm will install 'ng' under .\node_modules\.bin\
Your build definition could use the 'npm install' task to install locally 'ng', then you can invoke it by 'Command Line' task because you know the path to it (e.g. $(Build.SourcesDirectory)\node_modules\.bin).
Example of a build definition creating a new project and building it using 'ng':
install locally the 'ng' cli tool:
create the project 'helloworldproject':
build the project 'helloworldproject':
==Update (programmatically retrieve the actual binary path with 'npm bin')==
To remove the assumption where the binaries are placed and have a more resilient build definition, you could retrieve programmatically the actual binary path used by npm using the command:
>npm bin
The following example (this time a short PowerShell script) shows how to create the 'helloworldproject' and build it thereafter:
Remember:
to disable the option 'Fail on Standard Error' on the PowerShell task, as the ng tools likes to write stuff there even when it succeeds.
of course you still need the 'npm install' task as shown above before using the 'ng' tool.

I am currently going through the same thing so feel you pain.
You will probably have to create your own build server either as a VM on azure or on premise. The reason for this is that angular-cli isn't one of the capabilities of the hosted build server at present.
When you do create your own, you are still going to run into some hurdles. When you install angular-cli globally it still puts it under an AppData folder for the user that you install it with. If you have setup your agent to run as a different user for example NetworkService then for that service account "ng" wont be in the path. It will likely also not have permissions to run it because angular-cli has been installed under a user's folder for which it won't have permission.
Ok, so you run the agent with the same user or you resolve the permission and path issue you may still run into problems. If you use a powershell script task as one of your build tasks to perform "ng build" you will then run into the issue that I have highlighted here:
https://github.com/angular/angular-cli/issues/3979
So looks like we may have to resort to a command line build task instead.
Hope this helps. The last two days I have spent on this may as well help someone else.

Regarding Angular2-CLI command line, it uses ng2 instead of ng. (Angular-CLI uses ng), so your command is incorrect.
Refer to these steps to verify ng2 command (works on Hosted agent):
Add NPM build step (npm command: install; arguments: angular2-cli -g)
Add Command Line step (Tool: ng2; Arguments: --version)
If you are using on premise build agent with network service, using these steps instead:
NPM build step (npm command: install; Arguments: angular2-cli -g)
Command Line step (Tool: C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\npm\ng2.cmd; Argumetns: --version)
For on premise build agent with user account, you can log on that machine and install Angular2-CLI command line (do not need to install it during the build).

Related

Proxy error while installing Cypress on citrix machine

I am trying to install cypress on my Citrix machine using command npm install --save-dev cypress (It was working fine earlier) but now getting this error-
also, the same is working fine on my Local, But there is no proxy connection I am using to access internet in my citrix machine, not sure why suddenly it is throwing proxy error, I am not able to proceed further.
Follow the steps mentioned in the below for reference -
Pre-Requisites (Node JS & Package.json Creation -
Download VS Code latest one
Download Node from Node.js site to install
Once installed add New System Variable under windows Environment Variables as "Variable name" as NODE_HOME and "Variable value as C:\Program Files\nodejs
Go to the Project Folder and open in Command Prompt as below -
Then run command npm init
Enter Name as below as highlighted in yellow as cypressautomation -
Press Enter till below -
Then type yes Package.json file should get created
Restart Visual Studio Code
Clean Install of Cypress from Scratch - 1. Clear Cypress by searching in windows and Shift Delete(Excluding the project folders)
2. Download Cypress from https://download.cypress.io/desktop/9.5.2 (Pass any version based from - https://docs.cypress.io/guides/references/changelog
3.Use this command in VS Code terminal as setx CYPRESS_INSTALL_BINARY rojectfolder.zip (Copy this zip file to any location and mention the path after CYPRESS_INSTALL_BINARY)
4. Restart Visual Studio Code d. Run from terminal - npm install cypress#10.3.0 (This will install node_modules & package. lock.json)
5. \node_modules.bin\cypress.cmd install -- force
6. add the below command under scripts in package.json -
Cypress :run": "set Cypress RUN BINARY.C://Users//%username%// AppData//Local//Cypress//Cache//9.5.2//Cypress//Cypress.exe&& cypress open --browser electron (set CYPRESS_RUN_BINARY=mention the Appdata Path for cypress.exe)
We can figure out this issue using two steps.
step 1. Download cypress.zip file using URL that error has mentioned.
step 2 : run this command set CYPRESS_INSTALL_BINARY=yourPath\cypress.zip && npm install cypress

Azure DevOps CI pipe failure when executing script: ##[error]Cmd.exe exited with code '-1073741515'

I defined an Azure DevOps CI pipeline that deploys a database to Azure SQL Instance. After this step a script is run to update pip. I am doing all this to run unit tests on the deployed database.
script: |
python -m pip install --upgrade pip
displayName: 'Updating pip to latest version.'
This step is failing with;
##[error]Cmd.exe exited with code '-1073741515'.
I added user defined capabilities as seen in the image below. Initially I was targeting C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64 but that didn't work.
I had to copy Python3.9 into a directory x64 and create a version file. So I tried including pip thinking that perhaps the issue might be similar despite a different error message.
I also made sure that pip.exe is on the path.
There have been issues at every stage of the CI pipeline after migrating from a Microsoft Agent to a self-hosted agent on my local machine, those steps produced errors which were more verbose with messages that were less obtuse. I am struggling to find any useful information on this. It is an error that appears many different contexts making it further difficult to diagnose.

'npm' is not recognized as internal or external command, operable program or batch file

I am completely new to nodejs. I am trying to get nodejs to work on my Windows 2008 box in order to install Karma which I would use for TDDing my AngularJs code. I have done the following steps so far
Install using Chocolatey ==> npm is not recognised
Install using 64-bit nodejs installer from nodejs.org ==> npm is not recognised
At this stage, running where npm gives me c:\User\<Username>\AppData\Roaming\npm which has nothing in it
I figure out that nodejs is installed in C:\Program Files\nodejs. Opening a command prompt in this directory makes npm work fine.
So I added C:\Program Files\nodejs to PATH only to get the same error again that npm is not recognized
One of the github issues on nodejs repository says that I need to restart the machine and it would fix. But that has not helped so far
I do see a Node.js icon in my Start -> Programms mennu which takes me to nodejs console but not sure what to do with that.
Have I missed any important step in the process?
Edit
I figured out that if I open "Nodejs command prompt" from program files, then npm is recognized. How do I make it work on a normal command prompt?
Edit
After node I started facing a similar problem with another application. I posted this question on superuser and as rightly pointed out by the accepted answer, I had an additional quote in my PATH which was causing issues with all the paths added after the quote. I have a feeling that some Chocolatey install adds this troubling quote but I am just not sure which one.
Just add:
;C:\Program Files\nodejs\
To the end of your Path variable on the "User variable" section of the Environment Variables on the System Properties.
After that, reopen your command prompt and type
npm
This should work.
Don't forget to reboot your computer after installing node! That one got me.
If you are using VS Code, close VS code and open again.
I tried closing Terminal and then opening new Terminal but it didn't work.
Re-Starting VS Code works!
To elaborate on Breno's answer... For Windows 7 these steps worked for me:
Open the Control Panel (Click the Start button, then click Control Panel)
Click User Accounts
Click Change my environment variables
Select PATH and click the Edit... button
At the end of the Variable value, add ;C:\Program Files\nodejs
Click Ok on the "Edit User Variable" window, then click Ok on the "Environment Variables" window
Start a command prompt window (Start button, then type cmd into the search and hit enter)
At the prompt (C:\>) type npm and hit enter; you should now see some help text (Usage: npm <command> etc.) rather than "npm is not recognized..."
Now you can start using npm!
For Windows users: A picture tells a thousand words
Reference: npm not recognized as internal or external command (Note: this is my own blog)
Just Download and Install Node.js from here https://nodejs.org/en/
If you run the downloaded file and install it, they will automatically configure for your system
You don't need any other configurations anymore, now you can use the npm command anywhere
If the Nodejs is successfully installed and still displays the message like this:
'npm' is not recognized as an internal or external command, operable program or batch file.
Follow the steps below for Windows users:
Go to My Computer Properties
Click Advanced System Setting from the Left bar of a window.
Now you have a System Properties window. Click Advanced
Then, Click Environment Variable button
Now you have Environment variable window: From System Variable, Select Path
Click Edit
At the end of the Variable value, add ;C:\Program Files\nodejs\
Note: If you have installed nodejs on other drives then please act accordingly.
Click Ok all the open dialogue box
Very important Note: "Close your Command Prompt And Restart Again"
(It's very important because if you didn't restart your command prompt then changes will not be reflected.)
Now you can use the npm command anywhere
Don't forget to run cmd as admin.
I understand this question is really old and we have many answers, unfortunately, my scenario was different, thus a different solution.
If you started using nvm to manage the node versions after you install the node in your machine, most likely you will be facing the same issue.
I installed a version 10.15.3 and then I had to use another version as there is some tight dependency with one of my projects. Then I decided to install the nvm, while installing it asked, whether I need nvm to manage the version already installed on my machine which is 10.15.3. And yeah, I said Yes hoping that it will take care of that, unfortunately, it didn't.
I was always getting this error no matter I tried many other things mentioned in the other answers here, including setting the path. In the end, to fix that, these are the things I tried.
Uninstall the node version installed, for example, nvm uninstall 10.15.3
Make sure no other node versions are there, nvm list
Then, install the version needed, for example, nvm install 10.15.3. This should give you an output as preceding.
Downloading node.js version 10.15.3 (64-bit)...
Complete
Creating C:\Users\SibeeshVenu\AppData\Roaming\nvm\temp
Downloading npm version 6.4.1... Complete
Installing npm v6.4.1...
Installation complete. If you want to use this version, type
nvm use 10.15.3
PS C:\Users\SibeeshVenu> nvm use 10.15.3
Now using node v10.15.3 (64-bit)
Please note that from the above command, the npm is also installed.
Now use the version you need, nvm use 10.15.3 and type npm
I had the same problem described by Ashu, but in addition to that, the PATH entry for nodejs was terminated by a backslash:
C:\Program Files\nodejs\
I also had to remove that final backslash in order to have it work.
I faced the exact same issue and notice that after installing node.js there was a new path entry in the user variable section for PATH with value --> c:\User\\AppData\Roaming\npm. Also the Path entry in the system variable is appended with --> C:\Program Files\nodejs. Now since user variable has preference over system you have two options to fix this. Either delete the path from user variable or correct the right path (C:\Program Files\nodejs). Restart CMD and it should work.
Set aside all the tips, just run the following line in cmd
> SET PATH=C:\Program Files\Nodejs;%PATH%
If you're getting this error through a service account like Visual Studio TFS Build controller service or any other background service, make sure you restart the service after installing npm as the new PATH environment settings will not be picked up by those already running processes. I was getting same error through my build service but I had npm installed and running in the console.
You might have already received a response but this might help others since I experienced the same issue recently and this is what I did:
Added a path for Powershell. For me, the path was C:\Windows\System32\WindowsPowerShell\v1.0
Then, I opened the command prompt with administrative privileges and ran
#powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
Next, choco install nodejs
Restart and everything worked fine. Try opening the command prompt without admin privileges and run npm -v
Cheers.
Had the same problem on Windows 8.1 64 bit.
Turns out i get that problem if I start cmd by typing it in the path bar at the top of a folder window or when i shift right click in a folder window and then open command prompt from the list.
When I run cmd using Run or Just from the cmd.exe executable it works.
I installed nodejs following this AngularJS tutorial. the npm command did work when I open a new cmd window but not in the current one.
So the fix was to close and open a new cmd window.
If the package is successfully installed and still shows the message "'npm' is not recognized as an internal or external command, operable program or batch file."
Click windows start button.
Look for "ALL APPS", you will see Node.js and Node.js Command prompt there.
You can run the Node.js Command prompt as administrator and soon as its run it will show the message "Your environment has been set up for using Node.js 6.3.0 (x64) and npm."
and then it works from there...
I ran into this issue as well. It turns out Windows doesn't enjoy single quotes on the command line. The culprit was one of my npm scripts. I changed the single quotes to escaped double quotes:
'npm -s run sass-build'
to
\"npm -s run sass-build\"
I'm updating this thread with a new answer because I've found the solution to my miserable situation after not less than a week ...
For those still experiencing the error even though they have their path value set properly, check your pathext variable to have the value (default value in windows 7 +) : .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
Mine was to set only to : .BAT and changing it solved the problem. I wonder why nobody brought this up ...
Hope this helps!
If everything looks fine. I would advice to check this for PATHEXT .CMD must be added.
I don't know why most of user suggesting ; / in the command.
I solved this by removing ; and /
Before
;C:\Program Files\nodejs\
After Solution
C:\Program Files\nodejs
You need to save them into system PATH variables
I ran into this problem the other day on my Windows 7 machine. Problem wasn't my path, but I had to use escaped forward slashes instead of backslashes like this:
"scripts": {
"script": ".\\bin\\script.sh"
}
Step 1: install NodeJs
step 2: Set environment path
Step 3: Restart PC once
I installed Node.js and while trying to install Ionic and cordova using this piece of code:
npm install -g cordova ionic
I faced the above error. I added 'C:\Program Files\nodejs' to my Environment Variable 'PATH'. But still was unable to get over this issue. Turned out that my PATH variable was longer than 2048 characters and so I was unable to add the Nodejs path to it. I had to remove the path of another program and add the Nodejs path.
Close and reopen the cmd prompt and try to install Ionic again.
This worked for me.
for me adding path to PATH didn't do the trick.
Run c:\Program Files\nodejs\nodevars.bat instead, it will do the job for you
Well in my case doing testing via Mocha i tried everything just to realize i have to remove single quotes around my test case script tag inside package.json.
I am running mocha test case on all *.test.js files as can see below:
package.json
Before:
"scripts": {
"test": "mocha server/**/*.test.js",
"test-watch": "nodemon --exec 'npm run test'"
}
After(removing single quotes - npm run test):
"scripts": {
"test": "mocha server/**/*.test.js",
"test-watch": "nodemon --exec npm run test"
}
Worked for me, just in case someone else also gets stuck on this.
Check npm config by command:
npm config list
It needs properties: "prefix", global "prefix" and "node bin location".
; userconfig C:\Users\username\.npmrc
cache = "C:\\ProgramData\\npm-cache"
msvs_version = "2015"
prefix = "C:\\ProgramData\\npm"
python = "C:\\Python27\\"
registry = "http://registry.com/api/npm/npm-packages/"
; globalconfig C:\ProgramData\npm\etc\npmrc
cache = "C:\\ProgramData\\npm-cache"
prefix = "C:\\ProgramData\\npm"
; node bin location = C:\Program Files\nodejs\node.exe
; cwd = C:\WINDOWS\system32
In this case it needs to add these paths to the end of environment variable PATH:
;C:\Program Files\nodejs;C:\ProgramData\npm;
If you used ms build tools to install node the path is here:
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Microsoft\VisualStudio\NodeJs
You don't need to "install" Node.js. Just download the package from https://nodejs.org/en/download/releases/ and extract the contents somewhere. Then, in a command prompt, you can navigate there using cd. Then you can run npm from that location. While you will have to do the cd C:\Users\YourAcct\Documents\node-v16.13.0-win-x64 or similar command before you can run it, it's a way to get it onto your computer and run npm without having to be an admin or editing environmental variables.
The issue is with system policy. I have tried the following comments in powers heel then it is started working
$> Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
$> npm install -g npm-windows-upgrade
$> npm-windows-upgrade
I got this idea from the following link
After adding environment varible path restart your machine maybe this will work. it work for me. i was using vm.

Unable to get Docpad to run on Windows

I'm having problems getting Docpad to run on Windows.
I did the following.
Installed the latest version of Node
"NPM Install Docpad"
Then typed "docpad run" in an empty directory
I got an error message that said 'docpad' is not recognized as an internal or external command,
operable program or batch file.
Maybe I'm missing a step somewhere? I've also tried submitting the command to the node command prompt, and have also checked the troubleshooting guide and done a general google search.
Unless you installed an NPM module with the -g option (which is not indicated in the docpad web site so I suspect you didn't) the module won't be available on your PATH.
You can still run it by indicating the full path, for example run the following from the folder where you ran the npm install command:
node_modules\.bin\docpad.cmd
I had this same problem and a restart didn't help me.
What worked for me was installing via the 'nodejs command prompt' rather than the standard windows one.
I ran npm install -g docpad then navigated to my empty folder and ran docpad run and it worked straight away (after 1 hour messing around with the windows command prompt).

using jenkins to build RPM packages

I want to use Jenkins for creating RPM packages to deploy code and scripts onto a Linux redhat machine(s)
So the applications are a mix of technologies (no compiling needed) i just need to package up the applications deploy them to the correct location restart apache
Would anybody have some instructions on how to do these steps for a total Newbie:
Some questions:
Do i need to install jenkins on a local linux machine if im going to be creating RPM's that will be deployed on to linux redhat machine (i was hoping to install jenkins on windows)
Does anybody have a example of creating a package out of a local folder (no source control for the moment)
I want to just specify the directory of where to take the code from and specify where to deploy the code to on a machine the rpm is installed on
On the destination machine i want to run something like
yum -install mypackage-version12.rpm
and it will install the code/scripts to the specified directory and restart apache
i need an example of this also.
Thanks
You can install Jenkins on a different machine, but you generally must have a Jenkins "node", "slave", "agent" installed on a machine that can generate RPM packages.
Running each step of the RPM package setup is putting all the steps to build within Jenkins. It works much better if you extend your build system to build the RPM, and have Jenkins do what it does best, manage the build (schedule, etc), not micro-manage the build (do the steps).
Depending on what you currently have as your build system, this might include ant directives to setup the rpm build tree, copy in the .spec file, and a executable call to rpmbuild.
Jenkins can easily call a post-build task to do this, or you might want to configure a mini "fake" project that does the update, depending on tastes.
As an aside, for a yum command to work without using the --localinstall option, you will need to have a web server set up, the new RPM copied to the right folder on the web server, and the indexing files rebuilt (repobuild is the script to do so, if I recall correctly).
On the client machine (where the package will be installed), you will need to have a yum configuration that directs the client machine to include the web server as one of the known yum repositories.
Why not use an Docker images to build the RPM inside it though a dedicated stage ?
Your code needs to provide /rpm/SPEC files and inside the Docker (Jenkins) you can have a Jenkinsfile like :
mkdir -p ./rpm/BUILD && cd ./rpm/ && for f in ./SPECS/*; do rpmbuild --define \"_topdir \$(pwd)/\" --define \"_builddir \$(pwd)/BUILD\" -bb \$f;
And you are done.

Resources