15

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:

  1. 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.
  2. How could I be using the current option incorrectly?
  3. 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.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Chitra Belwal
  • 311
  • 1
  • 3
  • 7
  • 1
    Try ending your batch script with `exit /b 0` to 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` – rojo Dec 15 '14 at 17:47
  • Tried it, but no change. Still getting Unstable build. – Chitra Belwal Dec 18 '14 at 06:28
  • Hi Chitra, how did you resolve this issue. your help would greatly appreciated... – Nick Nov 17 '15 at 06:30

4 Answers4

17

This issue can be resolved by changing the Job configuration. When using Send Files or execute commands over SSH

Click on Advanced Tab.

Set Execution Timeout(ms): 0

This will help you in avoiding the timeout exception. It has worked for me, so hopefully it will work for you too. Exec timeout (ms) set to 0

PaulMest
  • 12,925
  • 7
  • 53
  • 50
Shivam Chandra
  • 171
  • 1
  • 2
14

Increase the timeout of SSH server configured in Manage Jenkins settings. Also the exec timeout in job configuration.

Shashi Ranjan
  • 1,491
  • 6
  • 27
  • 52
3

relate to Jenkins Text-finder unable to success my Build

enter image description here

  1. Into your job's configure page
  2. Roll down and In Post Steps SSH Publishers
  3. In Transfers Set, click advanced
  4. checked Exec in pty
alan9uo
  • 1,011
  • 1
  • 11
  • 17
山鬼谣
  • 41
  • 4
  • 14
0

rojo's suggestion of redirecting output worked for me. I appended this to my script:

>> /var/log/[project-name].log 2>&1

Mark
  • 181
  • 1
  • 3