Helix Core is now P4. Product user interfaces will be updated soon. Learn more >>

P4 Server Administration Documentation | 2025.1

# Creating triggers

This section explains the basic workflow used to create a trigger, describes a sample trigger, discusses the trigger definition, and examines a trigger’s execution environment.

To create a trigger and have P4 Server execute it, you must do the following:

1. Write the program or script. Triggers can be written in a shell script such as Perl, Python, or Ruby; or they can be written in any programming language that can interface with P4 Server, including UNIX shell and compiled languages like C/C+.

   Triggers have access to trigger variables that can be used to get server state information, execution context, client information, information about the parameters passed to the trigger, and so on. For information about trigger variables, see Trigger script variables.

   Triggers communicate with the server using trigger variables or by using a dictionary of key/value pairs accessed via STDIN and STDOUT. For more information on these methods, see Communication between a trigger and the server.

   Triggers can also use the command-line client (`p4.exe`) or the P4 Server scripting APIs (P4 API for Ruby, P4 API for Python, P4 API for PHP) when data is needed that cannot be accessed by trigger variables. Find the developer guide for the "P4 API" you want at https://www.perforce.com/support/self-service-resources/documentation.

   Triggers can be located on the server’s file system or in the depot itself, for information on using a trigger that is located in the depot, see Storing triggers in the depot.

   Triggers can be written for portability across servers. For more information, see Writing triggers to support multiple P4 Servers.

2. Use the `p4 triggers` command to create a trigger definition that determines when the trigger will fire. Trigger definitions are composed of four fields: these specify the trigger name, the event type that must occur, the location of the trigger and, in some cases, some file pattern that must be matched in order to fire the trigger.

   For more information, see Trigger definition.

When you use trigger scripts, remember that P4 Server commands that write data to the depot are dangerous and should be avoided. In particular, do not run the `p4 submit` command from within a trigger script.

It’s also important to avoid recursion and to watch out for client workspace locks. A trigger running commands as the requesting user could accidentally stall if it hits a lock.

Your search for returned results