{"id":1786,"date":"2013-06-11T10:51:19","date_gmt":"2013-06-11T15:51:19","guid":{"rendered":"http:\/\/www.kickflop.net\/blog\/?p=1786"},"modified":"2013-06-27T20:09:31","modified_gmt":"2013-06-28T01:09:31","slug":"jenkins-running-test-kitchen-via-vagrant-on-windows","status":"publish","type":"post","link":"https:\/\/www.kickflop.net\/blog\/2013\/06\/11\/jenkins-running-test-kitchen-via-vagrant-on-windows\/","title":{"rendered":"Jenkins running Test-Kitchen via Vagrant. On Windows."},"content":{"rendered":"<p>If you&#8217;re like me and for various reasons (we&#8217;ll not discuss) the physical hardware you have access to right now must run Windows, you might think you&#8217;re out of luck as far as getting Jenkins running Test-Kitchen jobs as Joshua Timberman shows in Test Kitchen and Jenkins<sup><a href=\"#references\">1<\/a><\/sup>. But there&#8217;s hope if you have patience. I&#8217;ll show how I got it working, and I&#8217;m looking forward to ideas from you on how to develop better solutions to some of the kludges. There&#8217;s not much original material here, but instead of mentioning just my piece of things and linking you coldly to 2 other places for the rest of the info, I figured I would write up as much of the whole experience as I felt up to.<!--more--><\/p>\n<h2>Prerequisites<\/h2>\n<h3>Windows Add-Ons<\/h3>\n<p>It is assumed that you have the following installed. If not, do so.<\/p>\n<ol>\n<li>Ruby 1.9.3 from <a href=\"http:\/\/rubyinstaller.org\/downloads\/\">rubyinstallers.org<\/a><\/li>\n<li>Git 1.8.x for Windows from <a href=\"http:\/\/git-scm.com\/download\/\">git-scm.com\/download<\/a>. All commands shown below are run under a &#8220;Git Bash&#8221; session and <strong>not Windows&#8217; cmd.exe!<\/strong> unless explicitly stated as such.<\/li>\n<li>Jenkins\n<\/ol>\n<h3>Ruby Gems<\/h3>\n<p>At this point, you should open a Git-Bash shell and ensure that <code>which gem<\/code> indicates the one found in the Ruby 1.9.3 install you did previously. For me, that was <code>\/c\/Ruby193\/bin\/gem<\/code>.<\/p>\n<p>Start with: <code>gem install bundler<\/code><\/p>\n<p>Then, in the directory containing the cookbook you want to test, create a <code>Gemfile<\/code> with the following contents:<\/p>\n<pre>\r\nsource 'https:\/\/rubygems.org'\r\ngem 'test-kitchen', '~> 1.0.0.alpha.7'\r\n<\/pre>\n<p>Run: <code>bundle install<\/code><\/p>\n<p>Run: <code>kitchen init<\/code><\/p>\n<p>Run: <code>bundle install<\/code> (yes, again)<\/p>\n<p>Run: <code>kitchen help<\/code> to ensure Test Kitchen can at least run.<\/p>\n<p>Edit <code>.kitchen.yml<\/code> to look like the following (configure later how you want):<\/p>\n<pre>\r\n---\r\ndriver_plugin: vagrant\r\ndriver_config:\r\n  require_chef_omnibus: true\r\n\r\nplatforms:\r\n- name: ubuntu-12.04\r\n  driver_config:\r\n    box: opscode-ubuntu-12.04\r\n    box_url: https:\/\/opscode-vm.s3.amazonaws.com\/vagrant\/opscode_ubuntu-12.04_provisionerless.box\r\n\r\nsuites:\r\n- name: default\r\n  run_list: []\r\n  attributes: {}\r\n<\/pre>\n<p>At this point you should be able to run <code>kitchen test<\/code> and see something success-like.<\/p>\n<h3>Jenkins<\/h3>\n<p>The Windows installer for Jenkins is nice in that it configures Jenkins to run as a Windows service. So go get and install that from <a href=\"http:\/\/mirrors.jenkins-ci.org\/windows\/latest\">jenkins-ci.org\/windows\/latest<\/a>. Once installed, you should be able to hit <code>http:\/\/localhost:8080<\/code> and see the Jenkins web UI.<\/p>\n<p>Use the web UI to install the &#8220;Git&#8221; plugin.<\/p>\n<p>Configure a new Jenkins job. For my case, it looked like the following.<\/p>\n<ul>\n<li>Source Code Management, Git Repositories, Repository URL: <code>git:\/\/github.com\/jblaine\/resolver.git<\/code> (use the <strong>Git read-only URL to the repo<\/strong>, not SSH, or you&#8217;ll have to mess with copying your SSH stuff similar to the problem section below regarding Vagrant)<\/li>\n<li>Build Triggers, Poll SCM, Schedule: <code>H 9-16\/2 * * 1-5<\/code><\/li>\n<li>Excute a Windows Batch Command: <code>kitchen test<\/code><\/li>\n<\/ul>\n<p>And click &#8220;Build now&#8221; at left to start the troubleshooting process below.<\/p>\n<h2>Problem: Jenkins can&#8217;t find Git<\/h2>\n<p>If you see in your job&#8217;s console output that Jenkins is not able to find Git, set the full path to the <em>executable binary<\/em> (regardless of the setting being called &#8220;Installation Directory&#8221;) as I did. This is the only thing that worked for me after trying a few other things found on the net.<\/p>\n<p>Oh, and you apparently have to use the old 8dot3 naming. No spaces allowed. What is this, 1999?<\/p>\n<p>Manage Jenkins, Configure System, Git, Git Installations, Installation Directory: <code>C:\\Progra~2\\Git\\cmd\\git.exe<\/code><\/p>\n<h2>Problem: Vagrant can&#8217;t import Boxes<\/h2>\n<p>Perhaps this is the next roadblock you hit:<\/p>\n<pre>\r\n...\r\nSTDOUT: Bringing machine 'default' up with 'virtualbox' provider...\r\n\r\n[default] Box 'opscode-ubuntu-12.04' was not found. Fetching box from specified URL for\r\nthe provider 'virtualbox'. Note that if the URL does not have\r\na box for this provider, you should interrupt Vagrant now and add\r\nthe box yourself. Otherwise Vagrant will attempt to download the\r\nfull box prior to discovering this error.\r\n\r\nDownloading or copying the box...\r\n\r\n...\r\n\r\nSuccessfully added box 'opscode-ubuntu-12.04' with provider 'virtualbox'!\r\n\r\n[default] Importing base box 'opscode-ubuntu-12.04'...\r\nSTDERR: There was an error while executing `VBoxManage`, a CLI used by Vagrant\r\nfor controlling VirtualBox. The command and stderr is shown below.\r\n\r\nCommand: [\"import\", \"C:\/WINDOWS\/system32\/config\/systemprofile\/.vagrant.d\/boxes\/opscode-ubuntu-12.04\/virtualbox\/box.ovf\"]\r\n\r\nStderr: 0%...\r\n\r\nProgress state: VBOX_E_FILE_ERROR\r\nVBoxManage.exe: error: Appliance read failed\r\nVBoxManage.exe: error: Could not read OVF file 'box.ovf' (VERR_PATH_NOT_FOUND)\r\nVBoxManage.exe: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component Appliance, interface IAppliance\r\nVBoxManage.exe: error: Context: \"int __cdecl handleImportAppliance(struct HandlerArg *)\" at line 306 of file VBoxManageAppliance.cpp\r\n---- End output of vagrant up --no-provision ----\r\nRan vagrant up --no-provision returned 1\r\n>>>>>> ----------------------\r\n>>>>>> Please see .kitchen\/logs\/kitchen.log for more details\r\n\r\nBuild step 'Execute Windows batch command' marked build as failure\r\nFinished: FAILURE\r\n<\/pre>\n<p>What&#8217;s telling here is that Vagrant is looking for boxes in <code>C:\\Windows\\System32<\/code> and not <code>C:\\Windows\\SysWOW64<\/code>. My wildly speculative guess is that this is because Vagrant is a 32-bit application and somehow this ties it to the different directory, even though the Jenkins service is tied to <code>C:\\Windows\\SysWOW64<\/code> by nature of the <code>LocalSystem<\/code> account.<\/p>\n<p>I&#8217;m pretty Windows-guts clueless as you can see. Any explanation you can share here, please do in the comments.<\/p>\n<p>At any rate, we persist. Using a <code>cmd.exe<\/code> that is run as Administrator, we look around:<\/p>\n<pre>\r\nC:\\>dir C:\\Windows\\System32\\config\\systemprofile\r\n Volume in drive C has no label.\r\n Volume Serial Number is 9424-87E5\r\n\r\n Directory of C:\\Windows\\System32\\config\\systemprofile\r\n\r\n06\/11\/2013  11:16 AM    &lt;DIR&gt;          .vagrant.d\r\n06\/11\/2013  11:19 AM    &lt;DIR&gt;          .VirtualBox\r\n10\/27\/2012  12:17 PM    &lt;DIR&gt;          AppData\r\n10\/27\/2012  12:17 PM           262,144 ntuser.dat\r\n06\/11\/2013  11:19 AM    &lt;DIR&gt;          VirtualBox VMs\r\n               1 File(s)        262,144 bytes\r\n               6 Dir(s)  279,382,310,912 bytes free\r\n\r\nC:\\>dir C:\\Windows\\System32\\config\\systemprofile\\.VirtualBox\r\n Volume in drive C has no label.\r\n Volume Serial Number is 9424-87E5\r\n\r\n Directory of C:\\Windows\\System32\\config\\systemprofile\\.VirtualBox\r\n\r\n06\/11\/2013  11:19 AM    &lt;DIR&gt;          .\r\n06\/11\/2013  11:19 AM    &lt;DIR&gt;          ..\r\n06\/11\/2013  11:19 AM            32,520 VBoxSVC.log\r\n06\/11\/2013  10:54 AM             1,114 VBoxSVC.log.1\r\n06\/11\/2013  10:47 AM               886 VBoxSVC.log.2\r\n06\/11\/2013  11:19 AM             1,066 VirtualBox.xml\r\n06\/11\/2013  11:18 AM             1,285 VirtualBox.xml-prev\r\n               5 File(s)         36,871 bytes\r\n               2 Dir(s)  279,382,302,720 bytes free\r\n\r\nC:\\>\r\n<\/pre>\n<p>Okay, so <em>some<\/em> VirtualBox stuff happened in <code>C:\\Windows\\System32<\/code>. But we can see that Vagrant has set up shop in <code>C:\\Windows\\SysWOW64<\/code>:<\/p>\n<pre>\r\nC:\\Users\\jblaine>dir C:\\Windows\\SysWOW64\\config\\systemprofile\\.vagrant.d\\boxes\r\n Volume in drive C has no label.\r\n Volume Serial Number is 9424-87E5\r\n\r\n Directory of C:\\Windows\\SysWOW64\\config\\systemprofile\\.vagrant.d\\boxes\r\n\r\n06\/11\/2013  10:54 AM    &lt;DIR&gt;          .\r\n06\/11\/2013  10:54 AM    &lt;DIR&gt;          ..\r\n06\/11\/2013  10:54 AM    &lt;DIR&gt;          opscode-ubuntu-12.04\r\n               0 File(s)              0 bytes\r\n               3 Dir(s)  279,808,155,648 bytes free\r\n\r\nC:\\Users\\jblaine>\r\n<\/pre>\n<p>Welp, I&#8217;m unaware of any environment variable that would allow me to tell Vagrant to use <code>C:\\Windows\\SysWOW64\\config\\systemprofile\\.vagrant.d<\/code>, so I just copied everything over to <code>C:\\Windows\\System32\\config\\systemprofile\\.vagrant.d<\/code>.<\/p>\n<h2>Success!<\/h2>\n<p>Rerunning the Jenkins build, you should now succeed, and at this point you would want to go back into your cookbook&#8217;s <code>.kitchen.yml<\/code> file to actually establish some tests to run in the <code>suites<\/code> section.<\/p>\n<pre>\r\n...\r\nC:\\Program Files (x86)\\Jenkins\\workspace\\test-resolver>kitchen test \r\n-----> Starting Kitchen (v1.0.0.alpha.7)\r\n...\r\n       [default] Importing base box 'opscode-ubuntu-12.04'...\r\n...\r\n-----> Converging <default-ubuntu-1204>\r\n-----> Installing Chef Omnibus (true)\r\n...\r\n[2013-06-11T15:19:39+00:00] INFO: *** Chef 11.4.4 ***\r\n...\r\n[2013-06-11T15:19:39+00:00] INFO: Chef Run complete in 0.009065059 seconds\r\n...\r\n-----> Kitchen is finished. (1m29.52s)\r\nFinished: SUCCESS\r\n<\/pre>\n<h2 name=references>References<\/h2>\n<dl>\n<dt>Test Kitchen Wiki<\/dt>\n<dd><a href=\"https:\/\/github.com\/opscode\/test-kitchen\/wiki\/Getting-Started\">https:\/\/github.com\/opscode\/test-kitchen\/wiki\/Getting-Started<\/a><\/dd>\n<dt>Test Kitchen and Jenkins<\/dt>\n<dd><a href=\"http:\/\/jtimberman.housepub.org\/blog\/2013\/05\/08\/test-kitchen-and-jenkins\/\">http:\/\/jtimberman.housepub.org\/blog\/2013\/05\/08\/test-kitchen-and-jenkins<\/a><\/dd>\n<dt>Jenkins Git Plugin (wiki page)<\/dt>\n<dd><a href=\"https:\/\/wiki.jenkins-ci.org\/display\/JENKINS\/Git+Plugin#GitPlugin-\">https:\/\/wiki.jenkins-ci.org\/display\/JENKINS\/Git+Plugin#GitPlugin-<\/a><\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re like me and for various reasons (we&#8217;ll not discuss) the physical hardware you have access to right now&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51,11,48],"tags":[],"class_list":["post-1786","post","type-post","status-publish","format-standard","hentry","category-devops","category-sysadmin","category-unixlinux"],"_links":{"self":[{"href":"https:\/\/www.kickflop.net\/blog\/wp-json\/wp\/v2\/posts\/1786","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kickflop.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kickflop.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kickflop.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kickflop.net\/blog\/wp-json\/wp\/v2\/comments?post=1786"}],"version-history":[{"count":10,"href":"https:\/\/www.kickflop.net\/blog\/wp-json\/wp\/v2\/posts\/1786\/revisions"}],"predecessor-version":[{"id":1804,"href":"https:\/\/www.kickflop.net\/blog\/wp-json\/wp\/v2\/posts\/1786\/revisions\/1804"}],"wp:attachment":[{"href":"https:\/\/www.kickflop.net\/blog\/wp-json\/wp\/v2\/media?parent=1786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kickflop.net\/blog\/wp-json\/wp\/v2\/categories?post=1786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kickflop.net\/blog\/wp-json\/wp\/v2\/tags?post=1786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}