August 24, 2007

Perforce Trigger To Update TestTrack

Helix ALM

Works with TestTrack 7.6 and later

Works with Perforce 2005.2 and later

This article outlines how to create a trigger in Perforce, which calls a script that updates TestTrack. This was all developed and tested against TT 7.6 and Perforce 2007.2. You'll need:
  • The TestTrack SOAP SDK installed.
  • The path to your TestTrack SDK installation. If you're familiar with how web servers work and your IT environment, you can probably guess this. If not, ask the TestTrack administrator or IT staff for help.
  • Perforce SCM and the necessary permissions to create triggers.
  • The path to your Perforce server.
You'll get:
  • A Perforce trigger that automatically associates committed changes with one or more defects in TestTrack.
What we'll do:
  • Review the script we're going to use to integrate with TestTrack.
  • Create a trigger to call the script.
  • Go through an example of using the new trigger.

Perforce Integration Script

The script we'll be using is written in Python. Python is good because it's easily installed and used on a variety of platforms. I'm not going to review the actual source, but it's not overly complex if you understand a little bit of Python and XML. If you need to enhance this script, I would not recommend using any of the Python SOAP libraries. I tried several of them in writing this script, and none of them worked as advertised. The common issue I ran into was lack of support for complex objects. Download Python Script The script requires 4 input parameters, listed below in the order they must be passed.
  • TT Project - Name of the TestTrack project you want to integrate to.
  • Username - Plaintext TestTrack username.
  • Password - Plaintext TestTrack password.
  • Changelist # - changelist number for the Perforce changelist to pull submit data from.
Once called, the script does the following:
  • Uses the p4 cli to fetch the referenced changelist.
  • Parses out the changelist comment.
  • Looks for the following token in the changelist comment: <ttp:defect#,{defect#>}.
  • If the token is found, parses out the files submitted with the changelist and links them to the SCC tab of each referenced defect.
For example, if you commit a changelist with <ttp:56,1065> somewhere in the comment, this script will attach all of the submitted files to defects 56 and 1065 along with the revision of each file. Other items of interest:
  • The path to the TestTrack SDK cgi is hard-coded in the script, around line 20 or so.
  • The path to the Perforce server is hard-coded in the script, at line 56.
  • You can call the script from a cmd-prompt to get basic help on using it.

Create Perforce Trigger

Now that we understand how to call the script, we can create a trigger in Perforce.
  1. Open a command-prompt
  2. type p4 triggers
  3. You should see Notepad or some other text editor pop up. If not, you'll need to read the Perforce documentation to figure out how to create a trigger on your version of Perforce.
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: SeapineTTP4 change-commit //depot/... "C:Pythonpython.exe p4 p4 p4 %changelist%" After a successful commit, our script should be called. We're connecting to a project by the name of "p4" as user "p4", with password the same. %changelist% is simply a variable that Perforce will replace with the actual changelist number, on every fire of the trigger.

Using the Trigger

Now we can actually use the trigger!
  1. Edit a file in Perforce.
  2. Right-click on the file's changelist and select commit.
  3. Enter <ttp:1> This is my first attempt at using the trigger that will integrate to P4!! as the changelist comment.
  4. Commit the changelist
Now you should have a file linked to defect #1 in your TestTrack project, on the SCC tab. If you've configure Perforce integration within TestTrack, you should be able to perform P4 commands on that file from within TestTrack as well. Note: Seapine does not provide support for sample triggers.