Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com Jun 3 '10 at 17:34

This question came from our site for professional and enthusiast programmers.

    
What does your Hudson log file say while the build is running and running ? Also, is anything printed out in the build log ? You might want to add some logging to your command.txt to see if it is starting to execute or not. –  gareth_bowles Jun 3 '10 at 15:51
    
I have updated my original post with the logs. ps: USER, PASS & SERV_ADD are replaced values. –  kij Jun 3 '10 at 16:32
add comment

4 Answers 4

up vote 1 down vote accepted

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.

share|improve this answer
    
Ok, Hudson is running with the local system. I've checked the option to work with the desktop, without success. In fact, i use username A to log on my local machine, and username B to log on the server machine (through putty or plink). So, the problem come from those two different usernames? As the server machine is not mine (Client one), i can't change my user account. Samme thing about my local account. I'll try to start Hudson server with my server username (and password), but i fear that it will lead other kind of errors. Anyway, thanks for your answer. –  kij Jun 7 '10 at 14:07
    
As i feared, using my server account to start Hudson didn't work, as this accound is not known on local network. So, about first "solution", if hudson is running with the local system and that the option 'interact with the desktop' is activated, even if i clean all my session keys and log to the server manually (and accept the key for the first time), then hudson job still can't access to the server without the key acceptance message :/ –  kij Jun 7 '10 at 14:27
    
Following prerequisites. First you yourself have to be an admin. Second you have to use a remote software like VNC, since they appear to Windows like a local login and not like an terminal server session. Following procedure, log into the server. After that start hudson and see if you get a popup. If not create a test-job with putty instead of plink and see if you get a popup. BTW, you can also ask a client admin if they can locally log into the server and accept the key. –  Peter Schuetze Jun 8 '10 at 20:42
    
Hi Peter, I've downloaded and use Quest's plink with the option -auto_store_key_in_cache and i works. Thanks for your help again (and Dave of course :)) –  kij Jun 10 '10 at 8:24
    
What exactly did you do with plink? Just run it? –  tim Jul 12 '10 at 19:03
show 1 more comment

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.

share|improve this answer
add comment

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.

share|improve this answer
    
Plink works fine from my command prompt. But from Hudson, it asks to accept the key to be registered in the registry. (as it's the first connexion to the server from Hudson) I tried to connect manually first in order to register the key... but it didn't ask me this question (from putty or plink). What should i do ? ps: The option -load doesn't work with my configured sessions. ps2: command line executed = plink -ssh SERVER -l USER -pw PASS -m SCRIPT –  kij Jun 4 '10 at 8:49
    
I cleanup putty session, and then connect again to my server. It ask me to store the key in cache, i accepted. Then i launch a build of my hudson job but again, same message to accept the key... So i think that from hudson, putty session are not working as attempted (same wrong behaviour than -load plink option) Are there other methods to connect to another machine from hudson, and execute shell scripts ? –  kij Jun 4 '10 at 9:47
add comment

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.

share|improve this answer
    
I already think to that way (the best i think), but i don't have rights to install Hudson slaves on the server. I've just seen your EDIT in previous post, i'll check tomorrow the option for automatically accept the auth key, i have to download new version of plink as mine is only 0.60 (0.60_q1... required for this option) Thanks again for your help. –  kij Jun 9 '10 at 16:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.