Posts Tagged ‘jenkins’


I had a great time figuring out how to checkout a GIT repository using jenkins under windows.
What caused me so much trouble was the ssh authentification.
Here are the steps a did to make it work.
I suppose you have a jenkins master machine and a slave building machine.

Install jenkins git plugins on your master machine

  • Git Client Plugin
  • Git Plugin
  • Git Server Plugin/li>
  • GitHub API Plugin
  • GitHub plugin
  • GitHub Pull Request Builder
  • Github Authentication plugin

Install git on your slave machine

On your slave machine install git command line application

http://git-scm.com/download/win

Add git to your Path system variable

  • Right-Click on My Computer
  • Click Advanced System Settings link from the left side column
  • Click Environment Variables in the bottom of the window
  • Then under System Variables look for the path variable and click edit
  • Add the pwd to git’s bin and cmd at the end of the string like this:
;C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Git\cmd

create a GIT_HOMEenvironement variable

In the same way create a variable named “GIT_HOME” pointing to your git bin folder:

C:\Program Files (x86)\Git\bin

Generate your private/public SSH keys with putty

First you need to download putty gen
Run it and click Generate button
Move your mouse around so that it can generate your keys using your mouse movements.
Once done create a folder on one of your drive called “.ssh”
Then you can save your private and public keys inside using the “Save public key” and “Save private key” buttons.
Don’t use credentials if you don’t want any console prompt when checking out with jenkins.
Note: When you save using those buttons it saves the data using putty own format.
What you want here is to get the key as an OpenSSH format.
For that you need to go in the menu bar “Conversions\Export OpenSSH key”. It will prompt for empty passphrase but it’s ok.
Then save the content into a file called something like id_rsa

Create git config file

On the “DRIVE:\.ssh” folder create a file called config (without any extensions)
Inside copy paste the following:

Host github_jenkins
	Hostname github.com
	User git
	IdentityFile D:\.ssh\id_rsa

Of course replace “D:\.ssh\id_rsa” by the location of your file containing your SSH key exported earlier.

Create a HOME environement variable

In the same way create a “HOME” environment variable pointing to the parent folder containing .ssh folder, (here “D:\“)

D:\

Configure Jenkins plugin

Go inside your jenkins system configuration page and in the git sub section make sure to point to your git binary folder as follow:
git_setup_1

Then look for your “GitHub Web Hook” sub section and make sure the “Manually manage hook URLs” is checked:
git_setup_2

Create GitHub token

Go to your gitHub web interface and inside your account settings, go to “Applications\Personal Access Tokens
Generate one and copy it.
Go back to your jenkins web interface, inside system configuration, go to the “GitHub pull requests builder
As “GitHub server api URL” put https://api.github.com if it’s not already there.
As “Access Token” place the key you have just generated.
Save your configuration.

Configure your Jenkins job

In your jenkins Job, go to your Source Code Management tab.
Click the “Git” option button.
on your repository address put

git@github_jenkins:MyRepositoryAddress.git

Note: github_jenkins is a hostname.
This hostname is written inside your [DRIVE]:\.ssh\config file after the “Host keyword”.
You can create as many hosts as you want and you can assign as many credentials as you have host names.

On the Branches to build text box you can enter the branch you want to build (origin/develop for example)

Alternatives

Here are some alternative links:


Why should we need the following template you will ask?
As JUnit is capable to generate it’s own report with the proper format, why should i need to generate this report myself?
To me the need is immediate:

  • When you create tests that can become very complex, and that you want to output the results the way you want, sometimes using a test framework such as JUnit or NUnit can be troublesome and not suitable.

For example, if you can perform a test with simple batch/shell script, because you want to test that your application or a part of your application generates the proper set of data or behave properly on your dedicated test system,you might want to avoid to create a special application using a test framework for this.

You can either create a generic application that generates this report for you with command line support, or write the report directly.

You may also just want to avoid any references to test frameworks and drive the tests the way you like.

As i can never know what xml format i need to provide to jenkins you can find the structure below:

<pre>
    <testsuite hostname="" name=""> <!-- testsuite is a mandatory tag -->
        <testcase classname="" name="" time=""> <!-- testcase is also mandatory, you need 1 per test/result, so if you have 10 result you need 10 -->
            <error message="error title"> <!-- optional Only needed on errors to describe the error/test failure -->
                Error Message, content ... <!-- optional, only needed to provide detailed information to jenkins -->
            </error>
           <skipped/> <!-- Optional, can only be present if <error> tag is not, to indicate that the current test was not processed but to keep track of it -->
        <!--testcase>-->
    <!--testsuite>-->
</pre>

The following is an example of a real report.

<pre><!-- hostname is an ID/name that identifies the system the test is running on -->
<testsuite hostname="ComputerName" name="StillImage"> 
    <testcase classname="Device.Initialize" name="StillImage_DVID_RGB Initialization" time="3"><!--testcase>     
    <testcase classname="Device.Status" name="StillImage_DVID_RGB status" time="3">
    </testcase>     
    <testcase classname="Grab.File size check" name="DVID_RGB_720p" time="0">
         <skipped/>
    </testcase>
    <testcase classname="Grab.File count check" name="DVID_RGB_720p" time="9">
         <error message="Error during grab process. (Occurs 134)">
             [Still image] Statistics : Succeeded : 5 | Asked : 20 | Missing : 15 | Success Percentage : 25
             [Still image] Statistics : Succeeded : 5 | Asked : 20 | Missing : 15 | Success Percentage : 25
         </error>
     </testcase>
 </testsuite> </pre>