Skip to content

Getting started with InvokeRemoteScript

rfennell edited this page Aug 3, 2014 · 5 revisions

This contribution is from Vinicius Moura.

See getting started page 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 running 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:

Screenshot

Customize Build Process Template

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

Screenshot

The full set of new required parameters are:

Parameter Value
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.

Screenshot

GetTeamProjectCollection

Screenshot

The full set of properties available are:

Parameter Value
DisplayName GetTeamProjectCollection
Result TeamProjectCollection

Download SSH Keys

Screenshot

The full set of properties available are:

Parameter Value
DisplayName Download SSH Keys Reg File
LocalPath System.IO.Path.Combine(buildDirectory, "SSHKeys.reg")
ServerPath "$//BuildProcessTemplates/SSHKeys.reg"
Version “T”
VersionControlServer TfsTeamProjectCollectionFactory.GetTeamProjectCollection(New Uri(TeamProjectCollection.Uri.ToString())).GetService(Of VersionControlServer)()
  1. Create a new variable called “SSHAuth” of type “TfsBuildExtensions.Activities.SSH.SSHAuthentication”.

Screenshot

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

Screenshot

a. Initialize SSH Auth

Screenshot

The full set of properties available are:

Parameter Value
DisplayName Initialize sshAuth
To sshAuth
Value New TfsBuildExtensions.Activities.SSH.SSHAuthentication()

b. Initialize SSH AuthenticationType

Screenshot

The full set of properties available are:

Parameter Value
DisplayName Initialize SSH AuthenticationType
To sshAuth.AuthType
Value SSHAuthenticationType.UserNamePassword

c. Initialize SSH User

Screenshot

The full set of properties available are:

Parameter Value
DisplayName Initialize SSH User
To sshAuth.User
Value UserName //this is a new parameter of Build Template

d. Initialize SSH Key

Screenshot

The full set of properties available are:

Parameter Value
DisplayName Initialize SSH Key
To sshAuth.Key
Value PassWord //this is a new parameter of Build Template
  1. After “Initialize SSH Key”, add the Build Activity “InvokeRemoteScript”. For this example, Build Template will run the Linux command “mkdir”.

Screenshot

The full set of properties available are:

Parameter Value
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.

Screenshot

Clone this wiki locally