1

I have a build box, which I use to make continuous builds as well as run nightly unit tests. I'm using Jenkins to do by builds/unit test scripts, which is running on a windows box because our compiler is windows based.

One of our enterprise solutions uses Python code with rabbitmq for exchanging messages for syncing specific database tables over a faulty network. I have unit tests to help verify that updates are happening correctly.

In order to unit test the Python updates, I need to be able to stop some services running on my Linux box, then restart them after I update the python code. I setup a key exchange between my Windows box and Linux box, so that I don't have to put a password in the batch script.

When I'm remoted into the windows box, I can successfully run the batch file, which uses plink commands which rely on the key exchange and putty's pageant (which is running in the background). e.g. I use plink to execute commands on the Linux box from command line in my batch file. However, when I try to run the batch file from Jenkins, the batch file doesn't work properly because it is prompted for the SSH password when trying to run the plink commands.

I believe my current issue can be summarized by two issues, which I'm hoping can be verified and rectified:

  1. I think Jenkins may be running as a different user or using different system credentials so it's not able to connect like the logged in user can. If this is the case, what would I need to do, to get it so that Jenkins can run the plink commands properly without being prompted for the password.
  2. Pageant looks like it needs to get a password typed in every time the computer restarts. My research unearthed ways to put Pageant in startup, so you get prompted when you first login, but I need this to be automatic, like how I can on Linux boxes. If Windows reboots because of a Windows update, then the unit tests would fail as they won't be able to connect to the Linux server. Sure this only happens once a week, but over the course of a year it'll be very annoying.

What can I do to solve the above two issues? If there is a good alternative to putty for the automatic key exchange between Windows and Linux, I'd be interested in hearing about it (I would prefer to stay away from Cygwin with OpenSSH, but might go down this route if the above can't be rectified).

halfer
  • 19,824
  • 17
  • 99
  • 186
James Oravec
  • 19,579
  • 27
  • 94
  • 160

2 Answers2

1

I use plink on my Windows Jenkins box to communicate with Linux on daily basis, there is no problem with it.

Like you theorized, Jenkins runs under it's own user (Windows default, I think, is SYSTEM user), which is different than your logged in session, even if you login as Administrator. Your authentication key is stored in your (Administrator or otherwise) profile directory

What you need to do is use Pageant to export your key as ppk file, then supply the path to this ppk file with plink:

plink -i "C:\path\to\id.ppk"

Slav
  • 27,057
  • 11
  • 80
  • 104
  • I updated my scripts to reference the .ppk but still get prompted for the passphrase... `Passphrase for key "jenkins to 10.2 key exchange": Lost connection` Thoughts? (I sued a ssh-rsa 2048), which works when I run directly from the machine, but not through the script... if I remove the key from pageant then run the bat file it gives the same prompt – James Oravec Sep 05 '14 at 21:48
  • I figured it out, I had to generate a new ppk wihtout a passphrase and then I was able to use that one to post. Thx. – James Oravec Sep 05 '14 at 23:23
0

Looks like there is a simpler way to do what I'm trying to do, Jenkin's plugin https://wiki.jenkins-ci.org/display/JENKINS/Publish+Over+SSH+Plugin

James Oravec
  • 19,579
  • 27
  • 94
  • 160
  • This seems like a good alternative, but I had the following issue and wasn't able to resolve it: http://stackoverflow.com/questions/22345483/jenkins-publish-over-ssh-authentification-failed-with-private-key leaving the post, in case they have a fix down the road. – James Oravec Sep 05 '14 at 21:44
  • The problem with Publish Over SSH Plugin (besides any technical issue you may have), is that you need to pre-configure all your servers in Global Configuration. If you got an environment where you have an arbitrary number of servers to connect to, that really doesn't work – Slav Sep 07 '14 at 05:21