Enhanced Perforce Integration
Works with TestTrack 2008 and later
Works with Perforce 2007.2
This article outlines how to implement a more enhanced integration with Perforce. In some previous examples, we've looked at how to trigger a defect update on P4 submit and prevent P4 submit based on defect status. Here we're going to look at a two-way integration between TestTrack Pro and Perforce that requires no special handling by a user.
- The TestTrack SDK installed.
- The path to the TestTrack SDK installation. If you're familiar with how web servers work and your IT environment, you can probably guess this. If not, ask your TestTrack administrator or IT staff for help.
- Working Perforce client/server installation.
- A working two-way integration between Perforce and TestTrack Pro.
DownloadThe download contains the source files and binaries for the application. Download the P4Sync zip file.
- SyncJob.exe - Executable built with C# .Net and Visual Studio 2005. The application handles all of the necessary integration points, and provides some flexibility in how you implement those integrations.
- Source Code - Visual Studio 2005 solution and all required source code to build the executable. You only need this if you want to make changes to the application or it doesn't work as-is in your environment.
How It WorksThe basic scenario this sample uses is:
- Create a Perforce job, that links back to one TestTrack Pro defect.
- Update the linked defect when the job is "fixed". This can be done from TestTrack or Perforce, both are supported within the sample.
Configure Perforce JobspecWe're going to link jobs with defects, so we need to customize the Perforce jobspec to support storing a defect number. We'll use a field called DefectNum, which requires just one line added to the spec, under the Fields header.
- 108 DefectNum word 32 default
Configure IntegrationOnce you've re-configured the P4 jobspec, you're ready to get started with the integration.
Create Perforce JobThe first step is to create a job/defect link between the two systems. We'll do this with a TestTrack trigger, so TestTrack is driving the integration. You can configure the trigger in any manner you want, including using multiple triggers. The goal here is to simply create a job in Perforce that links back to the defect that fired the trigger. TestTrack triggers don't allow cmd-line parameters, so first setup a bat file with the following contents
- C:JobSync.exe create
Sync Job Fix with DefectThe second piece of the integration requries that we update the defect once the associated job has been "fixed" in Perforce. You can accomplish this in a couple ways, as outlined below. Feel free to use either or both of these methods, as fits your process.
TestTrack TriggerThis trigger will pull the job fix information from Perforce, and update the associated defect. Here you get a one-to-many relationship for defects-to-jobs. An example would be you want to synchronize with job fixes when the defect is marked as Fixed in TestTrack Pro. Setup your batch file.
- C:JobSync.exe ttsync http://localhost/cgi-bin/ttsoapcgi.exe myuser mypwd
Perforce TriggerThis method will push Perforce submits to the associated TestTrack defects. Here we can support a many-to-many relationship for defects-to-jobs. We're going to create a post-commit trigger that calls our script to update TestTrack. The basic syntax here is: <trigger name> change-commit //depot/... <script> The trigger I created to test this: P4JobSync change-commit //depot/... "C:Pythonpython.exe C:JobSync.exe p4sync http://localhost/cgi-bin/ttsoapcgi.exe myuser mypwd myproj %changelist%" Now we're sending the p4sync flag and we're adding 2 additional parameters. Since we're not executing as a TestTrack trigger, you must specify the TestTrack project to update. Additionally, you need to specify the changelist that triggered execution.
Tech Details and NotesThis sample was written and tested using Perforce 2007.2 and TestTrack Studio 2008.
- The connection to Perforce is established using cached credentials from the system. If this doesn't work in your environment, you can update the source to specify connection data manually.
- The application uses the P4COM interface to interact with the Perforce server. The dll is included in the source, and is required to build the application (be sure to register it).
- Application logs are written to C:P4JobSync.log, which is hard-coded into the app.