-
Notifications
You must be signed in to change notification settings - Fork 30
Getting started with InvokeRemoteScript
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 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 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).
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 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:
Create four new required parameters on “SSH Build Template”.
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 |
After the solution is created, open “SSH Build Template” to add build Activity InvokeRemoteScript. 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
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 “InvokeRemoteScript”. For this example, Build Template will run the Linux command “mkdir”.
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 |
When a build run the Linux command, it displays on Build Message Log.