-
Notifications
You must be signed in to change notification settings - Fork 30
Getting started with FileCopyRemote
Note: Be sue to check out the following post from Giulio Vian Integrating Linux builds in TFS.
See the getting started page if this is your first time using the TFS Build Extensions.
Install and configure SSH Putty on your build server.
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.
To enable runing Linux commands on Build Activities, the latest release version of pscp software is required. After download, copy pscp Application on the same folder of SSH Putty (%ProgramFiles%/Putty).
To start the customization, a download of the Build Process Template is required. To use the Build Activity FileCopyRemote, 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 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 show bellow:
Customize Build Process Template
Create four new required parameters on “SSH Build Template”.
The full set of new required parameters are:
Parameter | Comment |
---|---|
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 FileCopyRemote in your build template
After the solution is created, open “SSH Build Template” to add build Activity FileCopyRemote. Follow the steps bellow:
- 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.
GetTeamProjectCollection
The full set of properties available are:
Parameter | Value |
---|---|
DisplayName | GetTeamProjectCollection |
Result | TeamProjectCollection |
Download SSH Keys Reg File
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)() |
- Create a new variable called “SSHAuth” of type “TfsBuildExtensions.Activities.SSH.SSHAuthentication”.
- After "Set TestStatus to Succeeded” of SetBuildProperties activity, initialize SSHAuth variable, SSHAuthenticationType, “SSH User” and “SSH Key” in “Assign Build Activity”.
a. Initialize SSH Auth
The full set of properties available are:
Parameter | Value |
---|---|
DisplayName | Initialize sshAuth |
To | sshAuth |
Value | New TfsBuildExtensions.Activities.SSH.SSHAuthentication() |
b. Initialize SSH AuthenticationType
The full set of properties available are:
Parameter | Value |
---|---|
DisplayName | Initialize SSH AuthenticationType |
To | sshAuth.AuthType |
Value | SSHAuthenticationType.UserNamePassword |
c. Initialize SSH User
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
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 |
- After “Initialize SSH Key”, add the Build Activity “FileCopyRemote”. For this example, Build Template will copy a source code stored on TFS to Linux.
The full set of properties available are:
Parameter | Value |
---|---|
Authentication | sshAuth |
KnowHostFile | """" + System.IO.Path.Combine(buildDirectory, "SSHKeys.reg") + """" |
Protocol | SSHCopyProtocol.sftp |
Recursively | True |
Source | """" + buildDirectory + "\src" + """" |
Target | """" + ServerDestination + ":" + FolderDestination + BuildDetail.BuildDefinition.Name.Replace(" ", "") + """" |
DisplayName | FileCopyRemote to Linux |
LogExceptionTrack | True |
When a build run the pscp command, it displays on Build Message Log.