How to run a batch file in a remote machine from the Teamcity - teamcity

I am building a C# project and deployed the package using Teamcity.
I have added a step in the build configuration that I need to execute a batch file present in the remote machine.
The batch file is copied to the remote machine along with the deployed package.
I am getting the error "The system cannot find the path specified."

If you are directly entering the path of the batch file, it will look for the same path on teamcity server and not on the remote machine.
you would have to install psexec on team city machine. See https://learn.microsoft.com/en-us/sysinternals/downloads/psexec
This command will help you to execute the script on remote machine
Now create a Command line step like this
and then in custom script use following :-
psexec \10.0.111.111 -d -accepteula -u domainname\userid -p password cmd.exe "Path/To/BatchFile.bat"
Here 10.0.111.111 is the ip adress of remote machine(Can use hostname as well).
domainname\userid is domain name and user id used to login the remote machine.
password is the password used to login remote machine.
Path/To/BatchFile.bat is the path to the batch file.

Related

Executing remote bat located on the remote computer

I need to execute a bat file located on several remote computers from my administration computer.
When I run it on the different remote computers I have no problem executing it.
When i run a "call myRemoteBat" from my local computer on all the remote ones my script doesn't run properly, raising for example the issue "foo not recongnized as an internal command"
Is there a way in the "call" command to execute using all the remote variables data?
Thanks

How to copy files to local machine from remote machine

My local machine is windows OS and remote machine is Linux based.
Have tried many tools to do the task but my main problem is the multilayer of authentication used.
I have to using putty first login to server 1 (first step of authentication) and then from server 1 login to the remote machine where required files are residing.
Please suggest
Download pscp from here: https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
Navigate to the folder where you downloaded pscp.exe.
Run command to download the file:
pscp -r user#192.168.1.10:/var/lib/file.txt C:\APPS
The answer is taken for here

How to invoke a remote vbs file from local machine?

I have copied a .vbs file to a remote machine which inturn invokes a local application.
Please suggest a way to invoke the remote vbs from the local machine.
I tried with wmi. I need to have UI
I know that this is an old post, but based on what you're saying, psexec from PsTools should do the trick.
You would use it in the following format:
psexec \\remote -u remoteuser -p password c:\scripts\script.vbs
For full information on psexec, see this TechNet article.

TeamCity error 'tscon.exe' is not recognized as an internal or external command

I'm using tscon.exe to unlock a remote machine locally before I can run automation tests. When I run my command via RDC it works as expected and unlocks the remote machine locally:
C:>tscon.exe %sessionname% /dest:console
But I need this to run as my first TeamCity build step. Doing so either as a direct TeamCity Custom Script or starting a .bat file, both return the error:
[16:50:22][Step 1/11] in directory: C:\BuildAgent\work\e4249c2d6a4e9e8d
[16:50:22][Step 1/11] 'tscon.exe' is not recognized as an internal or external command,
Why is tscon.exe not recognised when used via TeamCity?
I just had same issue and moving the exe out of System32 is not an option for me.So I have to dig deeper.
Turns out the problem is not Teamcity. It's windows.
"The windows filesystem redirection forces 32-bit application attempts to be installed into or accessed from %windir%\System32, been intercepted and get redirected or re-pointed to %windir%\SysWOW64 instead."
The solution is to use an alias name ( %windir%\Sysnative ) for that directory which windows will not redirected.
Try this :
C:\Windows\Sysnative\tscon.exe %sessionname% /dest:console
For more detailed Reference : http://www.tipandtrick.net/how-to-suppress-and-bypass-system32-file-system-redirect-to-syswow64-folder-with-sysnative/
Here is the solution:
Copy tscon.exe to any location other than %windir%\System32\
i.e. C:\TeamCity\tscon.exe
Add TC build step as below (ensure to include Working Dir):
Now the remote machine will login locally before completing the TC steps

Run batch scripts on a remote server (windows) from jenkins

I've got a continuous integration server (Jenkins ) which builds my code (checks for compilation errors) and runs tests and then deploys the files to a remote server (not a war file, but the actual file structure) I do this with a Jenkins plugin which allows me to transfer files via samba, it does this nightly.
Now, what I need to do is run an ant command on the remote server. And after that I need to start the application server on the remote server, the application server is started by running a .bat file from the command line.
I'm pretty clueless how to accomplish this, I know Jenkins is capable of running batch commands, but how do I make them run in the context of the server and not the context of the build server?
If Jenkins on Windows, remote on *nix, use plink.exe (which is essentially command line PuTTy)
If Jenkins on Windows, remote on Window, use psexec.exe
If Jenkins on *nix, remote on *nix, use ssh
If Jenkins on *nix, remote on Windows, (update 2015-01) Ansible http://docs.ansible.com/intro_windows.html has support for calling Windows commands, eg powershell, from a unix/linux machine, https://github.com/ansible/ansible-examples/blob/master/windows/run-powershell.yml
Tell me what OSes are involved (both on Jenkins and remote), and I will flash this out further.
Edit:
The download page for psexec.exe lists all command line options. You will want something along the lines of:
psexec \\remotecomputername -u remoteusername -p remotepassword cmd /c <your commands here>
Replace <your commands here> with actual commands as you would execute them from command prompt.
Note that psexec first needs to install a service, and required elevated command prompt/admin remote credentials to do so.
Also, you need to run psexec -accepteula once to accept the EULA prompt.
Following Slav's answer above, here is a simpler solution for Jenkins (*nix) to remote (windows):
Install an SSH server on your remote windows (MobaSSH home edition worked well for me)
Make sure your Jenkins user, on your Jenkins machine, has the required certification to open an SSH connection with your remote (you can simply open a terminal and ssh to your remote once, then accept the certification. Make sure it is saved for the Jenkins user).
You can now add an execute shell build phase in your Jenkins job which can SSH to your remote windows machine.
Notes :
The established connection might require some additional work - you might have to set windows environment variables or map network drivers in order for your executed commands or batch files to work properly on your windows machines.
If you wish to run GUI related operations this solution might not be relevant (Following my work on running automation tests which require GUI manipulation).
Using Jenkins SSH plugin is an issue, as seen here.
1、i install (MobaSSH home ) on my remote windows server .
2、and install jenkins ssh plugin
3、edit shell eg: go build project
4、it seems something wrong ,
" go: creating work dir: CreateFile C:\WINDOWS\system32\bsh\tmp: The system cannot find the path specified."
I ended up going with a different approach after trying out psexec.exe for a while.
Psexec.exe and copying files over the network was a bit slow and unstable, especially since the domain I work on has a policy of changing password every months (which broke the build).
In the end I went with the master/slave approach, which is faster and more stable. Since I don't have to use psexec.exe and don't have to copy files over the network.

Resources