Jenkins: run batch locally on slave - batch-file

I need Jenkins to be able to run batch file on slave locally with parameters. I've tried to use PSExec tool, but it does not run when Jenkins tries to do it (slave: windows 7 x86 OS). xCmd cannot be run locally. Can anybody suggest some tools or some way to do it?

PSExec works for me on Windows 7 x64. Solved.

Related

Running batch file from network share (vmware shared folder) in cygwin

I'm having some problems with cygwin and a mapped network drive. My setup is kind of convoluted to deal with some limitations with our corporate VPN. I'm running a Windows 10 VM under VMware Fusion with a shared folder from my Mac host which is mapped to a network drive in Windows. The reason is b/c I access a remote Git repo using a VPN connection that leverages a browser plugin that unfortunately is only working from Safari currently. I need to run git commands from the Mac host but the project's build/development environment is Windows. The VPN browser plugin fails to install in any of the browsers under Windows. Hopefully a temporary problem but one I must workaround for now.
From my cygwin environment the mapped drive does not show up under /cygdrive, possibly b/c it's a shared folder with hgfs file system type. I'm able to mount the shared folder but when I try to run a batch file from the cygwin environment I get the following error:
./OpenCommandPrompt.bat
'\\vmware-host\Shared Folders\grant\Projects\lts\Product'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
The system cannot find the path specified.
'setenv.bat' is not recognized as an internal or external command,
operable program or batch file.
'setclasspath.bat' is not recognized as an internal or external
command, operable program or batch file.
C:\Windows>
It doesn't like the UNC path. I'm able to run the command fine from a PowerShell using the mapped drive letter but no luck from cygwin. My desire is to run the VM headless and access the Windows environment over SSH from my host so I'd like to get this working from the cygwin environment if possible. Any suggestions?
I was able to fix my issue by creating a simple script that I execute from my .bash_profile. I basically check for existence of the /cygdrive/h folder and if it doesn't exist I execute the script.
#!/bin/bash
net use H: '\\vmware-host\Shared Folders\share'
I tried to map the drive from Windows but all attempts to do so failed to register the drive mapping under the /cygdrive folder in cygwin. That was the issue I was trying to overcome. Once I had the mapped drive under /cygdrive, I was able to execute all the batch scripts.
To be honest, I'm still not sure why mapping the drive from Windows does not register it cygwin. The reverse is also true: if I execute the net command from the terminal, it does not register in Explorer.

How to run a batch file from Jenkins

I am trying to run a batch file from Jenkins but I can't get it to run.
In the pre-build step I have entered the file I want to execute but I get the stacktrace shown below. Jenkins doesn't recognize the cmd command.
How can I fix this?
Your Linux Jenkins slave doesn't support cmd. In order to workaround it you have several options (from better to worse):
Add a Windows slave to Jenkins and run cmd from there.
Port your batch file to bash or similar and run it from your Linux Jenkins slave.
Add some kind of DOS emulator (Wine, DOSBox, DOSemu) in your Linux Jenkins slave.
My advice: If you know Linux & Bash or you have no control of Jenkins go for option 2. Otherwise go for option 1. Avoid option 3.
You're trying to run CMD on a LINUX machine. either change the slave you're running to Windows machine or migrate the Batch script to shell script.
Good luck!

Running CMD as admin to uninstall driver

I am trying to run an uninstall command for several remote computers. Is there a way to run CMD as admin to run a script that uninstalls the driver I need it to?
I was using PSEXEC and i can connect to all the computers but I it won't run the batch file i have to uninstall the driver as admin.
Any help would be great!
You can do this by pressing windows key x and selecting open command prompt as administrator

Batch script not doing anything when execute from remote machine using ssh

i'm having a problem while executing batch script from linux machine.
Scenario:
I've a windows machine installed server2008, I need to automate some windows task that executes from linux machine. I've installed cygwin software on windows VM and create a batch script that is running fine from cygwin terminal. i.e cd ~/;./script.bat
Problem:
When I execute the same script from linux machine using ssh it seems works fine and print script executed successfully but when I checked that the task from windows it did nothing.
cat script.bat
#echo off
set sourcePasswd=%1
set destinationPasswd=%2
set destinationProjectName=%3
set user=%4
set xmlPath=C:\cygwin\home\%user%\Duplicate.xml
ECHO Start : Duplication project source for %destinationProjectName%
"C:\Program Files (x86)\Common Files\MySoftware\Duplicate.EXE" -f %xmlPath% -sp %sourcePasswd% -dp %destinationPasswd% -sup -md -dn %destinationProjectName%
ECHO Finish : Duplication project source for %destinationProjectName%
Looks like Leopard hasn't been back since he posted the question or the link to the answer, so I'll be the Point Pimpette tonight and fill in the blank.
The answer below is from the link:
http://cygwin.com/ml/cygwin/2010-07/msg00598.html
It was fixed after doing the following setup :
Open control panel=> Administrative Tools=>Computer
Management=>Services
lookup the sshd service, right
click=>properties=>log on, and check the checkbox for Allow service
to interact with desktop
restart the service.
thanks
Saravana

Batch: Running files through ssh on Windows machines

What I'm trying to do might be simple for veteran programmers. I have two Windows machines: MachineA and MachineB. From MachineA, I want to:
1) ssh into MachineB, run a batch file say C:\parent\test.bat -start
2) delete C:\parent folder
3) Copy C:\parent folder from MachineA to the C drive in MachineB
4) Run C:\parent\test.bat -stop
5) I need to do all the above through a script on MachineA (preferably a Batch Script)
Most of what I've read so far about this uses plink or other software (someone suggested WinSCP).
It would be nice if I could do all this WITHOUT installing any software. Any suggestions??
(I do have msysgit on both machines)
SSH is not supported by windows. You will have to install a utility to run a command on a remote machine
You can find details in this post:
How to execute a dos command on a remote PC?
Your other option is to use Windows Powershell scripts.

Resources