activate a trigger in a depot
accurev mktrig [ -p <depot-name> ] [ pre-create-trig | pre-keep-trig |
pre-promote-trig | server-post-promote-trig ] <program-or-script>
The mktrig command creates a trigger within a particular depot. A trigger can “fire” before or after certain AccuRev transactions occur. The following triggers are defined on a per-depot basis, affecting operations only with that particular depot:
fire on the client machine, before an add transaction
fire on the client machine, before a keep transaction
fire on the client machine, before a promote transaction
fire on the server machine, after a promote transaction
When a trigger fires, it executes the trigger program or trigger script that you specify in the mktrig command. The names of all elements involved in the transaction are passed to this program or script as part of a parameters file.
mktrig does not make a copy of the trigger script. It simply records the location at where AccuRev will look for the script when the trigger fires.
Note: The trigger script need not exist at the specified location when you issue the mktrig command. AccuRev doesn’t look for the script until the trigger fires.
A trigger fires exactly once per transaction. If you do a keep operation on 10 elements and there is a pre-keep trigger set, the trigger script will execute once, with an argument list containing all 10 element names. It is the script’s responsibility to process its entire argument list.
By acting once for the entire transaction, the script can abort a transaction if there is a problem with any element in the transaction, or you can send out a single email message with a list of all of the elements, instead of a separate message for each element in the transaction. For a transaction with 100 elements, that's a real benefit!
When the trigger script executes, its exit value should be 0 (success) or non-zero (failure). When a pre-operation trigger script fails, execution of the AccuRev operation is canceled.
Location of the Trigger Program or Script
The trigger script must be installed in a place that is accessible to everyone that will be using a depot with the trigger enabled. Separate copies of the script can be placed on each client machine. A better procedure is to place all scripts in a central, network-wide location that all client machines can “see” (UNIX/Linux mount or Windows network share). If triggers will fire on both Windows and UNIX/Linux machines, be sure to read Notes on Triggers in Multiple-Platform Environments in the AccuRev Admin Guide.
When a trigger fires, AccuRev looks for a script at the location you specify in the mktrig command. A pre-transaction trigger fires on the client machine:
- AccuRev searches for the trigger script on the client machine, in the directories on the user’s search path.
- The script executes on the client machine, with the user’s identity.
A post-transaction trigger fires on the server machine:
- AccuRev searches for the trigger script on the server machine, using the search path of the “server account”: the user account that runs the accurev_server process — typically, acserver (UNIX/Linux) or System (Windows).
- The script executes on the server machine, with the server-account identity.
Note: AccuRev uses a search path to locate the trigger script if you specify a simple name or a relative pathname for the script in the mktrig command (this is our recommendation); if you specify an absolute pathname for the script, no search path is involved.
The ‘server_preop_trig’ and ‘server_admin_trig’ Trigger Scripts
The triggers described above operate on a per-depot basis. For example, a pre-create-trig trigger might be activated in depot gizmo, but not in depot whammo. Two additional triggers execute on the AccuRev server machine:
- The server_preop_trig script executes before the command is executed, and can cancel the command altogether. This is a per-depot trigger.
- The server_admin_trig script executes after the command is executed. This script cannot cancel execution of the command. This trigger applies to AccuRev commands irrespective of which depot, if any, is being addressed. Note that the server_admin_trig script applies to all depots.
You enable these triggers not with the mktrig command, but by installing the trigger scripts at well-known locations. For details, see Server-Side Triggers in the AccuRev Admin Guide.
AccuRev’s issue management facility, AccuWork, also supports triggers. See server_dispatch_post in the AccuRev Admin Guide.
Specify the depot in which the trigger is to be enabled (default: the depot of the current workspace).
Execute Perl script elem-type.pl before each add transaction:
> accurev mktrig pre-create-trig /usr/local/triggers/elem-type.pl
Execute Perl script addheader.pl before each keep transaction:
> accurev mktrig pre-keep-trig /usr/local/triggers/addheader.pl
AccuRev Triggers in the AccuRev Admin Guide.