Skip to content

Commit

Permalink
new post
Browse files Browse the repository at this point in the history
  • Loading branch information
mcrmfc committed Jun 28, 2013
1 parent 2161384 commit ac48f6f
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 2 deletions.
2 changes: 1 addition & 1 deletion _includes/tag_cloud.html
@@ -1 +1 @@
<a href="/tags/android" title="Postings tagged android" style="font-size: 10.5px; line-height:10.5px">android</a> <a href="/tags/browsermob" title="Postings tagged browsermob" style="font-size: 10.5px; line-height:10.5px">browsermob</a> <a href="/tags/bundler" title="Postings tagged bundler" style="font-size: 11.0px; line-height:11.0px">bundler</a> <a href="/tags/capybara" title="Postings tagged capybara" style="font-size: 13.0px; line-height:13.0px">capybara</a> <a href="/tags/ci" title="Postings tagged ci" style="font-size: 10.5px; line-height:10.5px">ci</a> <a href="/tags/cpaybara" title="Postings tagged cpaybara" style="font-size: 10.5px; line-height:10.5px">cpaybara</a> <a href="/tags/cucumber" title="Postings tagged cucumber" style="font-size: 14.5px; line-height:14.5px">cucumber</a> <a href="/tags/grid" title="Postings tagged grid" style="font-size: 10.5px; line-height:10.5px">grid</a> <a href="/tags/gvim" title="Postings tagged gvim" style="font-size: 10.5px; line-height:10.5px">gvim</a> <a href="/tags/javascript" title="Postings tagged javascript" style="font-size: 10.5px; line-height:10.5px">javascript</a> <a href="/tags/qunit" title="Postings tagged qunit" style="font-size: 10.5px; line-height:10.5px">qunit</a> <a href="/tags/ruby" title="Postings tagged ruby" style="font-size: 13.0px; line-height:13.0px">ruby</a> <a href="/tags/selenium" title="Postings tagged selenium" style="font-size: 14.0px; line-height:14.0px">selenium</a> <a href="/tags/testing" title="Postings tagged testing" style="font-size: 20.0px; line-height:20.0px">testing</a> <a href="/tags/ubuntu" title="Postings tagged ubuntu" style="font-size: 10.5px; line-height:10.5px">ubuntu</a> <a href="/tags/vim" title="Postings tagged vim" style="font-size: 11.0px; line-height:11.0px">vim</a> <a href="/tags/webdriver" title="Postings tagged webdriver" style="font-size: 14.0px; line-height:14.0px">webdriver</a> <a href="/tags/webkit" title="Postings tagged webkit" style="font-size: 10.5px; line-height:10.5px">webkit</a>
<a href="/tags/android" title="Postings tagged android" style="font-size: 10.5px; line-height:10.5px">android</a> <a href="/tags/browsermob" title="Postings tagged browsermob" style="font-size: 10.5px; line-height:10.5px">browsermob</a> <a href="/tags/bundler" title="Postings tagged bundler" style="font-size: 11.0px; line-height:11.0px">bundler</a> <a href="/tags/capybara" title="Postings tagged capybara" style="font-size: 13.0px; line-height:13.0px">capybara</a> <a href="/tags/ci" title="Postings tagged ci" style="font-size: 11.0px; line-height:11.0px">ci</a> <a href="/tags/cpaybara" title="Postings tagged cpaybara" style="font-size: 10.5px; line-height:10.5px">cpaybara</a> <a href="/tags/cucumber" title="Postings tagged cucumber" style="font-size: 14.5px; line-height:14.5px">cucumber</a> <a href="/tags/grid" title="Postings tagged grid" style="font-size: 10.5px; line-height:10.5px">grid</a> <a href="/tags/gvim" title="Postings tagged gvim" style="font-size: 10.5px; line-height:10.5px">gvim</a> <a href="/tags/javascript" title="Postings tagged javascript" style="font-size: 10.5px; line-height:10.5px">javascript</a> <a href="/tags/jenkins" title="Postings tagged jenkins" style="font-size: 10.5px; line-height:10.5px">jenkins</a> <a href="/tags/qunit" title="Postings tagged qunit" style="font-size: 10.5px; line-height:10.5px">qunit</a> <a href="/tags/ruby" title="Postings tagged ruby" style="font-size: 13.0px; line-height:13.0px">ruby</a> <a href="/tags/selenium" title="Postings tagged selenium" style="font-size: 14.0px; line-height:14.0px">selenium</a> <a href="/tags/testing" title="Postings tagged testing" style="font-size: 20.0px; line-height:20.0px">testing</a> <a href="/tags/ubuntu" title="Postings tagged ubuntu" style="font-size: 10.5px; line-height:10.5px">ubuntu</a> <a href="/tags/vim" title="Postings tagged vim" style="font-size: 11.0px; line-height:11.0px">vim</a> <a href="/tags/webdriver" title="Postings tagged webdriver" style="font-size: 14.0px; line-height:14.0px">webdriver</a> <a href="/tags/webkit" title="Postings tagged webkit" style="font-size: 10.5px; line-height:10.5px">webkit</a>
82 changes: 82 additions & 0 deletions _posts/2013-06-28-jenkins-windows-ssh.markdown
@@ -0,0 +1,82 @@
---
layout: post
title: Git Clone via SSH using Jenkins on Windows
author: Matt Robbins
categories:
- ci
- jenkins
---

This blog post is nothing revolutionary but more of a note to self so that I never have to learn this painful lesson again!

My current team has Windows specific CI dependencies, hence I had no choice but to setup our Jenkins instance on Windows. The cleanest way to do this is to use the [Jenkins Installer](https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+as+a+Windows+service) which installs Jenkins as a Windows Service.

That works fine, but of course the first challenge you face is cloning your Git repo over SSH (the default for the Jenkins Git plugin).

I'll assume you have done the following:

* Installed [Git Client](https://code.google.com/p/msysgit/downloads/list)
* Created [SSH Keys](https://help.github.com/articles/generating-ssh-keys#platform-windows) and ensured that you can successfully clone a repo from your Git Bash (running as current user).

Note: In theory you should not use passwordless keys as anybody obtaining your key will have access to your account. However for Jenkins you cannot have a password as the Job would hang when attempting to clone. From Git Bash this problem is solved using [ssh-agent](https://help.github.com/articles/working-with-ssh-key-passphrases#platform-windows) but this won't work in Jenkins as we are using the Git plugin and not the shell.

Bottom line - for Jenkins use a passwordless key - you can mitigate the risk by having a dedicated Jenkins Git User and only allowing them pull access.

* Set up the Git plugin in Jenkins via 'Manage Jenkins' and point it to the Git cmd file on the system, as in the screenshot below:

![jenkins_git_plugin](/images/jenkins_git_plugin.png)


Now we get to the tricky part. When Jenkins runs as a Windows Service it does not run under a normal user account, it runs under the "Local System Account". Hence even though you have Git Clone working as the current user it will fail in Jenkins.

To solve this problem we need to put our private ssh key in the correct location for the Local System Account.

First of all we need to find out where this user's home directory is, since it will not exist under C:\Users...

* Download [PSTools](http://download.sysinternals.com/files/PSTools.zip)
* Extract to a conventiant location and using a command prompt navigate to that location (or add to path if you prefer)
* Start the PsExec tool by running:

{% highlight console %}
PsExec.exe -i -s cmd.exe
{% endhighlight %}

* Now we need to find out where this user's home directory is:

{% highlight console %}
echo %userprofile%
{% endhighlight %}

* For me this location was:

{% highlight console %}
C:\Windows\system32\config\systemprofile
{% endhighlight %}

* Now you can open Git Bash within this shell by running the following command:

{% highlight console %}
C:\Program Files (x86)\Git\bin\sh –login –i
{% endhighlight %}

* You can copy your existing private key into the correct location for the Local System User, for me this was something like the following:

{% highlight console %}
cd ~
cp /c/Users/matt/.ssh/id_rsa ~/.ssh/
{% endhighlight %}

* Finally you can test that you can successfully authenticate to Github as the Local System User:

{% highlight console %}
ssh -T git@github.com
{% endhighlight %}

* If all is successful you should see the usual message:

{% highlight console %}
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
{% endhighlight %}


All that's left to do now is test from Jenkins...Huzzah!
Binary file added images/jenkins_git_plugin.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion sitemap.xml
Expand Up @@ -14,7 +14,11 @@
</url>
<url>
<loc>http://opensourcetester.co.uk/tags.html</loc>
<lastmod>2012-12-06</lastmod>
<lastmod>2013-06-28</lastmod>
</url>
<url>
<loc>http://opensourcetester.co.uk/2013/06/28/jenkins-windows-ssh</loc>
<lastmod>2013-06-28</lastmod>
</url>
<url>
<loc>http://opensourcetester.co.uk/2012/11/29/zeros-padding-3des-ruby-openssl</loc>
Expand Down
9 changes: 9 additions & 0 deletions tags.html
Expand Up @@ -55,6 +55,10 @@ <h3 id="android">android</h3>
<div>03 Aug 2012</div>
<a href="/2012/08/03/pass-parameters-hudson">Passing parameters to a downstream Hudson (Jenkins) job</a>
</li>
<li>
<div>28 Jun 2013</div>
<a href="/2013/06/28/jenkins-windows-ssh">Git Clone via SSH using Jenkins on Windows</a>
</li>
</ul> <h3 id="cpaybara">cpaybara</h3>
<ul class="posts"> <li>
<div>06 Aug 2012</div>
Expand Down Expand Up @@ -104,6 +108,11 @@ <h3 id="android">android</h3>
<div>30 Jun 2011</div>
<a href="/2011/06/30/qunit-selenium-sauce">Qunit in the cloud - with Selenium Webdriver, RC and SauceLabs</a>
</li>
</ul> <h3 id="jenkins">jenkins</h3>
<ul class="posts"> <li>
<div>28 Jun 2013</div>
<a href="/2013/06/28/jenkins-windows-ssh">Git Clone via SSH using Jenkins on Windows</a>
</li>
</ul> <h3 id="qunit">qunit</h3>
<ul class="posts"> <li>
<div>30 Jun 2011</div>
Expand Down

0 comments on commit ac48f6f

Please sign in to comment.