This contribution is from Vinicius Moura.

 

See How to integrate the community build extensions into your build process template if this is your first time using the TFS Build Extensions.

Install and configure SSH Putty

Install and configure SSH Putty on your build server.

Recover and export Putty Register

After SSH Putty is installed, access Windows Registry (regedit.exe), export and save a key pointed in “HKEY_CURRENT_USER\Software\SimonTatham\PuTTY” and name it as SSHKeys.reg. Save this file on “Build Process Templates” folder in your Source Control.

Download plink Software

To enable runing Linux commands on Build Activities, the latest release version of plink software is required. After download, copy plink Application on the same folder of SSH Putty (%ProgramFiles%/Putty).

Download Build Process Template

To start the customization, a download of the Build Process Template is required. To use the Build Activity InvokeRemoteScript, download the “Upgrade Template.xaml”, rename it as “SSH Build Template.xaml” and store it on “Build Process Templates” folder in your Source Control.

Create a Visual Studio Solution

Create and store a Visual Studio Solution on “Build Process Templates” folder to manipulate a Build Template. This project will reference TFS Build Extensions and other libraries as shown bellow:

clip_image002

Customize Build Process Template

Create four new required parameters on “SSH Build Template”.

clip_image004

The full set of new required parameters are:

ServerDestination

Host Name of Linux connection

FolderDestination

Folder Destination that it executes the Linux command

UserName

User Name of Linux connection

PassWord

Password of Linux connection

Integrate the build activity InvokeRemoteScript in your build template

After the solution is created, open “SSH Build Template” to add build Activity InvokeRemoteScript. Follow the steps bellow:

1. It´s required to execute a download of Putty register (SSHKeys.reg). To perform this operation, use the Build Activity GetTeamProjectCollection together with Build Activity DownloadFile. Put these Build Activities on “Run on Agent” sequence.

clip_image006

clip_image008

clip_image010

   

The full set of properties available are:

DisplayName

GetTeamProjectCollection

Result

TeamProjectCollection

clip_image012

clip_image013

The full set of properties available are:

DisplayName

Download SSH Keys Reg File

LocalPath

System.IO.Path.Combine(buildDirectory, "SSHKeys.reg")

ServerPath

"$/<Team Project Name>/BuildProcessTemplates/SSHKeys.reg"

Version

“T”

VersionControlServer

TfsTeamProjectCollectionFactory.GetTeamProjectCollection(New Uri(TeamProjectCollection.Uri.ToString())).GetService(Of VersionControlServer)()

2. Create a new variable called “SSHAuth” of type “TfsBuildExtensions.Activities.SSH.SSHAuthentication”.

clip_image015

3. After "Set TestStatus to Succeeded” of SetBuildProperties activity, initialize SSHAuth variable, SSHAuthenticationType, “SSH User” and “SSH Key” in “Assign Build Activity”.

clip_image017

a. Initialize SSH Auth

clip_image019

clip_image021

The full set of properties available are:

DisplayName

Initialize sshAuth

To

sshAuth

Value

New TfsBuildExtensions.Activities.SSH.SSHAuthentication()

b. Initialize SSH AuthenticationType

clip_image023

clip_image025

The full set of properties available are:

DisplayName

Initialize SSH AuthenticationType

To

sshAuth.AuthType

Value

SSHAuthenticationType.UserNamePassword

c. Initialize SSH User

clip_image027

clip_image029

The full set of properties available are:

DisplayName

Initialize SSH User

To

sshAuth.User

Value

UserName //this is a new parameter of Build Template

d. Initialize SSH Key

clip_image031

clip_image033

The full set of properties available are:

DisplayName

Initialize SSH Key

To

sshAuth.Key

Value

PassWord //this is a new parameter of Build Template

4. After “Initialize SSH Key”, add the Build Activity “InvokeRemoteScript”. For this example, Build Template will run the Linux command “mkdir”.

clip_image035

clip_image036

The full set of properties available are:

Authentication

sshAuth

KnowHostFile

"""" + System.IO.Path.Combine(buildDirectory, "SSHKeys.reg") + """"

Command

"""" + "mkdir -p " + FolderDestination + BuildDetail.BuildDefinition.Name.Replace(" ", "") + """"

Host

ServerDestination //this is a new parameter of Build Template

DisplayName

Create Dir On Linux

LogExceptionTrack

True

Running the Build

When a build run the Linux command, it displays on Build Message Log.

clip_image038

Last edited Feb 9, 2014 at 11:19 AM by mikefourie, version 3

Comments

No comments yet.