Setting up Jenkins on Windows with Git, Mercurial and SSH.
Monday 29 Aug 2016 at 21:00
Development
|
ci
windows
git
mercurial
ssh
This guide will detail the steps required to correctly setup and configure Jenkins on Windows using both Git and Mercurial as the version control tools and using SSH with both in order to authenticate with repositories hosted on the BitBucket service.
- Download and install Jenkins, Git & Mercurial to their default locations. Ensure you get the 64-bit versions of all of these tools.
- First, we need to create an SSH key pair, using OpenSSH which comes bundled with Git, that will allow Git to communicate with Bitbucket via SSH.
- Next, we’ll configure OpenSSH (which is used by Git), so follow the steps under the section “Set Up SSH for Git” from here: https://confluence.atlassian.com/bitbucket/set-up-ssh-for-git-728138079.html
- This primarily involves creating a new ssh keypair from a Git Bash shell, using
ssh-keygen
, ensuring the resulting keys are stored in your user’s “home” directory (which on Windows is usually,C:\Users\xxxxx\
- where xxxx is your logged on Windows username) within an.ssh
directory and that you have aconfig
file within that same folder that tells Git/SSH which key to use for a specific host (i.e.Host bitbucket.org IdentityFile ~/.ssh/<privatekeyfile>
) - Next, we need to configure Mercurial. Since Mercurial is a more “windows-y” tool, by default, it wants to use PuTTY (and its related tools of Plink and Pageant), however, we’re going to tell Mercurial to use OpenSSH instead. Normally, you would edit a mercurial.ini file inside the installation folder of TortoiseHg (usually,
C:\Program Files\TortoiseHg\
) however, this didn’t seem to work for me, as Hg insisted on pulling the required config from a different file which constantly overrode anything I had set in the mercurial.ini file! The file in question that is likely to need to be edited isC:\Program Files\TortoiseHg\hgrc.d\Paths.rc
Within this file, you’ll need to add or amend the[ui]
section to configure ssh:
[ui]
ssh = ssh -2 -C -x
- Note that the above assumes that the path for SSH (which, since it’s installed with Git, is usually
C:\Program Files\Git\usr\bin
. If this path isn’t added to your PATH environment variable for SYSTEM (not for a specific user) then you’ll need to add it. Open Control Panel, go to “System”, click “Advanced System Settings” in the left-hand menu, then click the button “Environment Variables” on the resulting dialog. Remember to edit theSystem Variables
not the ones for your user). - Jenkins, when installed on Windows, is by default configured to run as a Windows Service. The service is configured to run under the
Local System
account. As a result of this, Mercurial will invoke OpenSSH in this context, and so OpenSSH will now look to theLocal System
account’shome
directory for it’s SSH keys (Git seems perfectly happy looking for the keys in the user’shome
folder). So, take the entire.ssh
folder from the user’shome
folder (the same folder as used earlier when creating the ssh-keys initially) and copy them to theLocal System
account’shome
folder. Where is this? Well, it’s not within theC:\Users\
area, not even as a hidden/system folder, oh no, that would be too logical. So, Windows, in it’s infinite wisdom decides to place theLocal System
account’shome
folder here:C:\Windows\System32\config\systemprofile\
- After this, you should be able to start Jenkins and add some build jobs. When creating the jobs, you’ll set the relevant
Source Code Management
to either Git or Mercurial, and you’ll specify anssh://
protocol address for theRepository URL
. Note that you do NOT need to specify anything within the credentials (i.e. leave it set to it’s default value of--none--
) section here as when Jenkins “shells” out to the relevant SCM tool, that tool will be given anssh://
address to connect to and that tool’s configuration will look to see how it is configured to accessssh://
URLs. It’s that configuration that will provide the necessary credentials to connect to the remote repository.
Search
Categories
Tags
conferences (27)
development (27)
dotnet (21)
ddd (20)
c# (8)
asp.net (8)
microsoft (6)
razor (5)
certification (5)
database (4)
ssh (4)
sql (3)
cloud (3)
ssl (3)
bitbucket (3)
github (3)
intellisense (3)
extensions (3)
aws (2)
jquery (2)
knockout (2)
windows (2)
mercurial (2)
javascript (2)
powerbi (1)
analytics (1)
staticanalysis (1)
software (1)
review (1)
visualstudio (1)
analysis (1)
codeclones (1)
entityframework (1)
mysql (1)
automapper (1)
upgrade (1)
binding (1)
select (1)
validation (1)
putty (1)
hosts (1)
ci (1)
git (1)
nuget (1)
files (1)
encoding (1)
stacked (1)
azure (1)
owin (1)
authorisation (1)
webapi (1)
mvc (1)
web (1)
testing (1)
security (1)
sourcecontrol (1)
administrator (1)
keyboard (1)
motivation (1)
autonomy (1)
fizzbuzz (1)