1

I'm trying to use PuTTY on the command line from an Hudson job.

The command is the following one:

putty -ssh -2 -P 22 USERNAME@SERVER_ADDR -pw PASS -m command.txt

Where 'command.txt' is a shell script to execute in the server through SSH.

If I launch this command from the Windows command prompt, it works. The shell script is executed on the server machine.

If I launch a build of the Hudson job configured with this batch command, it doesn't work. The build is running... and running... and running.. without doing anything, and I have to stop it manually.

Is it possible to launch an external program (that is, PuTTY) from a Hudson job?

PS: I tried SSH plugin but... not a really good plugin (pre/post build, fail status of the commands launched not caught by Hudson, etc.)

These are the build logs:

[workspace] $ cmd /c call C:\WINDOWS\TEMP\hudson7429256014041663539.bat

C:\Hudson\jobs\Artifact deployer\workspace>putty -ssh -2 -P 22 USER@SERV_ADD -pw PASS -m com.txt 
Le build a été annulé
Finished: ABORTED

And the Hudson.err.log file at the same time (after a stop):

3 juin 2010 18:27:28 hudson.model.Run run
INFO: Artifact deployer #6 aborted
java.lang.InterruptedException
    at java.lang.ProcessImpl.waitFor(Native Method)
    at hudson.Proc$LocalProc.join(Proc.java:179)
    at hudson.Launcher$ProcStarter.join(Launcher.java:278)
    at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:83)
    at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:58)
    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:19)
    at hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:601)
    at hudson.model.Build$RunnerImpl.build(Build.java:174)
    at hudson.model.Build$RunnerImpl.doRun(Build.java:138)
    at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:416)
    at hudson.model.Run.run(Run.java:1241)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:124)

My shell script only write "hello" in a "hello.txt" file on the server, and nothing is done.

kij
  • 121

4 Answers4

1

PuTTY creates a window. That's probably why it's hanging for Hudson (which doesn't have access to the windowing system). Plink is probably a better bet. However, with my PuTTY install (0.60), Plink's command-line options are completely broken. I couldn't log into a server other than with my PuTTY defaults.

In theory, you could set up a PuTTY session and use that with Plink (via -load). However, you'll have the problem of getting your configured session into whatever user Hudson is running as.

1

The problem is, that you need to accept the key with the username that you run Hudson with. So in case you don't run Hudson with the local system account (which is a bad idea anyway) you have to log in with the Hudson account and accept the key. Then your Hudson build will work.

If Hudson is running with the local system account there might be an option, but I am not sure if it will work or not. First, you have to allow the Hudson service to interact with the desktop. Then you log into your server as an admin. I am not sure if you need to be physically on the box. Launch Plink or PuTTY and hope that a pop up will appear, then you can accept the key and everything should work fine.

Another option would be to launch Plink with the runas command and supply your (different) user credentials.

Another option is: get Quest's Plink and use the option -auto_store_key_in_cache.

1

As Peter Schuetze pointed out, you have to accept the key with the username that you run Hudson with. My solution for this, just using the standard putty and plink, is this:

  1. Setup a session using the connection details you need with putty and save it
  2. connect once, accepting the key
  3. With regedit, export [HKEY_CURRENT_USER\Software\SimonTatham] completely
  4. Replace "HKEY_CURRENT_USER" with "HKEY_USERS\S-1-5-18", which is the security identifier for the Local System account
  5. Save the .reg file and import it by double-clicking

By doing that you now have the accepted host key AND all settings for the session available when doing plink connections with the local system account.

Comes in handy especially when you also set a private key file which is not password protected for that session.

Tolo
  • 11
  • 1
0

My favorite way to get into the context of another machine is to create a slave on the target machine and run the scripts. I use that extensively to get around storing passwords unencrypted on hard-drives. Have a look at the hudson documentation on how to do that.