Configuring triggers to attach changelists from Perforce P4 clients to Perforce ALM items
You can configure Perforce P4 triggers to attach changelists to Perforce ALM items from P4 clients. When users submit changelists from clients, they can include the tag for the ALM item to attach the changelist to in the description. A trigger runs, verifies that the specified item exists, and then attaches the changelist to the item. See Attaching changelists to items from Perforce P4 clients.
Attached changelists are displayed on the item Source Files tab in ALM. If the P4 Code Review URL is configured for the P4 provider in the ALM project, you can click a hyperlink to open the changelist in P4 Code Review. See Viewing source control changelists.
Perform the following steps to configure ALM and triggers to attach changelists to items.
1. Review the requirements for using triggers.
2. Add a P4 provider to the ALM project.
3. Download and modify the attachToHelixALM Python script. The script retrieves information from P4 and sends it to the ALM source control provider CGI.
4. Add trigger definitions to P4.
On this page:
Requirements
Make sure the following components are installed to use changelist attachment triggers.
- Perforce ALM 2017.1 or later
- Perforce ALM external source control provider CGI (ttextpro.exe) on the web server that hosts ALM CGIs. See the installation documentation for information.
- Perforce P4 with P4 API for Python. P4 API for Python may require additional DLLs. See the P4 API for Python documentation for information.
- Python 3.5
You must also enable external source control provider access in the Perforce ALM Registry Utility to send attachment information from P4 to ALM. See the registry utility documentation for information.
Downloading and modifying the trigger Python script
The triggers to attach changelists to ALM items run from a Python script stored on the P4 Server. After downloading the script, modify it to include information about your P4 and ALM configurations.
1. Download the script and save it on the computer that hosts P4.
2. Edit the following configuration variables in the script.
| Variable | Description | Example |
|---|---|---|
| EXTERNAL_PROVIDER_URL | URL for the ALM source control provider CGI on your web server (e.g., http://localhost/cgi-bin/ttextpro.exe). | EXTERNAL_PROVIDER_URL = ‘http://localhost/cgi-bin/ttextpro.exe’ |
| SSL_CERTIFICATE_MODE | Indicates how triggers connect to the web server hosting the ALM source control provider CGI. If the web server enforces HTTPS and has a valid certificate, use ssl.CERT_REQUIRED. If the web server has a self-signed certificate, use ssl.CERT_NONE to prevent HTTPS from failing and returning an error that the certificate is not trusted. | SSL_CERTIFICATE_MODE = ssl.CERT_REQUIRED |
| SSL_PROTOCOL_MODE | SSL protocol that the web server supports. The default value is ssl.PROTOCOL_SSLv23, which supports SSL, SSL2, SSL3, and TLS. | SSL_PROTOCOL_MODE = ssl.PROTOCOL_SSLv23 |
| PROVIDER_KEY | Key from the P4 provider configured in the ALM project. Copy the key from the Source Control Providers dialog box and paste it in the script. | PROVIDER_KEY = ‘{123456-abc-789-efghijk}:{abcdef-123-ghi-456789}’ |
| P4PORT | Port number for P4. Must be a string. | P4PORT = ‘1666’ |
| P4USER | P4 user to log in when the trigger connects to the server. | P4USER = ‘Administrator’ |
| P4PASSWD | Password for the P4 user used to log in to the server. | P4PASSWD = ‘p@ssword’ |
| ISSUE_TAG TEST_CASE_TAG REQUIREMENT_TAG |
ALM item abbreviations that identify which items to attach changelists to. You can use the default tags or specify different tags if item types are renamed in the project. Default tags: IS for issues, TC for test cases, and RQ for requirements. If you do not know the abbreviations to use, you can find them in the Rename Field Labels dialog box. | ISSUE_TAG = ‘IS’TEST_CASE_TAG = ‘TC’ REQUIREMENT_TAG = ‘RQ’ |
3. Save the script.
Adding trigger definitions
You need to add definitions for the trigger to run from the p4 triggers command.
1. At a command prompt on the computer that hosts P4, enter p4 triggers.
A temporary file that contains trigger information opens.
2. Add the following lines to the file.
Keep the following in mind:
- The change-submit and change-commit lines support P4 and Edge configurations.
- Replace <DepotName> with the depot name to configure the trigger for.
- Replace <PythonPath> with the location of the attachToHelixALM.py script.
- Whitespace is required at beginning of each command.
- %changelist% is replaced with the changelist number when the trigger runs.
check-ALM-item-exists-on-change change-submit //<DepotName>/... "<PythonExePath>\attachToHelixALM.py %changelist% verify"
attach-to-ALM-item-on-change change-commit //<DepotName>/... "<PythonExePath>\attachToHelixALM.py %changelist%"
check-ALM-Item-exists-on-push push-submit //<DepotName>/... "<PythonExePath>\attachToHelixALM.py %changelist% verify"
attach-to-ALM-item-on-push push-commit //<DepotName>/... "<PythonPath>\attachToHelixALM.py %changelist%"
3. Save the file.
The trigger definitions are copied to P4.
Example
check-ALM-item-exists-on-change change-submit //streamsDepot/... "C:\python35\python C:\ALMTrigger\attachToHelixALM.py %changelist% verify"
attach-to-ALM-item-on-change change-commit //streamsDepot/... "C:\python35\python C:\ALMTrigger\attachToHelixALM.py %changelist%"
check-ALM-Item-exists-on-push push-submit //streamsDepot/... "C:\python35\python C:\ALMTrigger\attachToHelixALM.py
attach-to-ALM-item-on-push push-commit //streamsDepot/... "C:\python35\python C:\ALMTrigger\attachToHelixALM.py %changelist%"