Install program on custom build agent azure devops - windows

I have downloaded a custom build agent for an Azure Devops release pipeline. I am trying to execute a sed statement within the release pipeline, but I am getting an error that the term sed is not recognized as the name of a cmdlet, function, script file, or operable program. Any advice on how I can get sed installed in a custom build agent would be appreciated.

As per the error message, you are running sed in powershell task.
Please change to use Bash task as it's a unix based command.
Since you're using self-hosted agent, please make sure you have installed mingw(you can install git for windows(git bash) which include mingw) on windows machine, run sed --version locally, make sure it can run successfully. Follow link to add "C:\Program Files\Git\bin" to the Path of Environment Variables, then restart the agent service. You can invoke bash in pipeline now.
My local command:
My pipeline with bash task:

Related

Using WSL2 to execute jenkins scripts made for linux nodes

We have been using linux test bots so far in Jenkins and have made groovy scrpts that call bash scripts to execute tests. Now we need to add Windows test bots to the pool but we cant start WSL from the script.
Is there any way to use WSL instead of bat / powershell to run bash commands in jenkins pipelines?
using for example wsl -l or wsl + one command works, but just executing the command wsl from the code does not give any error.
Manually triggering wsl from cmd / powershell on the device directly works without any issues.

Heroku: heroku is not recognized as an internal or external command, operable program or batch file

As you can probably tell by the title, I am having difficulty with Heroku. Whenever I run heroku --version in the Command Line, I receive the error 'heroku' is not recognized as an internal or external command, operable program or batch file. I have tried uninstalling and re-installing heroku multiple times, to no success. I have included screenshots of the download steps which I took.
Specs:
Windows v10.0.18363.1198, 64-bit
heroku CLI v7.47.3
Git v2.29.2.windows.2
Download Steps:
Make sure that you add the path to heroku to PATH. In this case it would be C:\Program Files (x86)\heroku\client\bin
Make sure you restart your system and run your command again, worked for me earlier.
After the restart, check your Heroku version use heroku -v in terminal or CMD.

Commands in git-lab-runner on windows machine not working

I have a gitlab-runner installed on my windows 10.
When I try to use commands like pip and sh in my .gitlab-ci.yml file the runner does not recognize these commands even though they are recognized in my windows machine when run using cmd.
All the environment variables have been setup properly on my windows machine.
i.e pip works on my windows machine but not on my gitlab-runner.
Refer this link
My config.toml file has been set to "cmd".
Error seen: 'pip' is not recognized as an internal or external command,
operable program or batch file.
setting
before_script:
- SET SH_HOME=C:\cygwin64
resolved the issue referring this question

Angular CLI VSO 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).

Jenkins not playing nice with a private GitHub repository (Windows)

I cannot for the life of me seem to get my Jenkins CI to work with Github.
I had failure on the clone command, but that was due to keys, so I logged in as service account (the user Jenkins runs under as a Windows Service) and ran the clone command. All good in the hood.
However, when I want to run the fetch to get latest, it won't finish. It just sits there. I have tried via the Git plugin for Jenkins, and also via a Windows commandline script. Neither work. However, if I open a command prompt and type the command in, it works!
So how do I get it to work via Jenkins?
I run this script:
set
"C:\Program Files (x86)\Git\bin\git.exe" fetch -t ssh://git#github.com/OrgName/MyRepo.git +refs/heads/*:refs/remotes/origin/*
exit 0
and it sticks on the fetch command, never exiting.
Does someone have any suggestion?
It looks like msysGit stuck trying to find one of its components, used during fetch operation.
The Git itself not a single executable actually. It's a set of small tools doing their job great only being put together. Running Git on Windows from bash prompt makes it happen, but when you're running via Windows command prompt or in batch-files, the Force may not be with you.
I think you should check wherever you installed msysGit with option "Run Git from Windows Command Prompt". In this case all needed parts of Git will be added to the system PATH variable and git.exe will be able to access it from batch files, thus it should fix your fetch statement.

Resources