I need to create a Jenkins job that runs a PowerShell script on another server over SSH. I am using 'Send files or execute commands over SSH' option to do the needful. The 'Exec command' field has value "cmd /c XCopy.bat" where XCopy.bat (batch file present on the other server - Windows server 2008 R2 - where my SSH is installed) in turns runs the PowerShell. The job is simply to copy a folder and its content to another location.
When I build the job, the copying is done as desired. However, the job terminates in Unstable build. Here are the logs:
SSH: Connecting from host [USVAUJNKW001]
SSH: Connecting with configuration [54.254.146.206-SGSGDAPPW001] ...
SSH: EXEC: STDOUT/STDERR from command [cmd /c XCopy.bat] ...
**copy job done**
SSH: Disconnecting configuration [54.254.146.206-SGSGDAPPW001] ...
ERROR: Exception when publishing, exception message [Exec timed out or was interrupted after 120,012 ms]
Build step 'Send files or execute commands over SSH' changed build result to UNSTABLE
Finished: UNSTABLE
I have tried different 'Exec timeout (ms)' values and (un)checked 'Exec in pty' but to no success.
Queries:
- Is there any other option in Jenkins through which I can accomplish the task i.e. to simply run a PS script on another server via SSH.
- How could I be using the current option incorrectly?
- Do I need to make changes, if any, at batch/PS file level to return some code that tells the Jenkins that job is complete and it should exit successfully?
I have tried to find answers on different forums but none has been exactly useful.


exit /b 0to force a status code of 0 on exit. See whether that makes your SSH job understand that there were no errors. Also, within your batch script, any program that writes to stdout or stderr, pipe the output to NUL like this:2>&1>NUL