Additional triggers for push and fetch commands

The section Triggering on pushes and fetches describes the triggers that you can run during the various phases of the p4 push and p4 fetch commands. These are command triggers that are run by the server initiating the push or the fetch. However, for every initiator, there is a responder:

  • For every push by server A to server B, there is a server B receiving the items pushed by A.
  • For every fetch by server A from server B, there is a sever B that is being fetched from.

This creates additional trigger opportunities for the server receiving the push and the server responding to the fetch request. You can use command type triggers to take advantage of these opportunities. Within this context:

  • pre-user and post-user actions refer to the server initiating the push or fetch.
  • pre-rmt and post-rmt actions refer to the responding server.

The responding (or remote -rmt-) server can use these triggers:

Trigger Run this trigger on the remote server

pre-rmt-Push

Before it receives pushed content

post-rmt-Push

After it receives pushed content.

Two special variables are available for use with post remote push triggers:

  • %firstPushedChange% specifies the first new changelist number
  • %lastPushedChange% specifies the last new changelist number

pre-rmt-Fetch

before it responds to a fetch request

post-rmt-Fetch

After it responds to a fetch request

The following table describes the fields for the trigger definition.

Field Meaning

name

The name of the command trigger.

type

command

path

The pre-user-command value specifies the command before which the trigger should execute.

The post-user-command value specifies the command after which the trigger should execute.

Examples of possible values:

  • pre-rmt-Fetch

  • post-rmt-Fetch

  • pre-rmt-Push

  • post-rmt-Push

command

The trigger for Helix Core Server to run when the condition implied by path is satisfied.

Specify the command in a way that allows Helix Core Server to locate and run the command. The command (typically a call to a script) must be quoted, and can take as arguments anything that your command is capable of parsing, including any applicable Helix Core Server trigger variable.

When your trigger script is stored in the depot, its path must be specified in depot syntax, delimited by percent characters. For example, if your script is stored in the depot as //depot/scripts/myScript.pl, the corresponding value for the command field might be "/usr/bin/perl %//depot/scripts/myScript.pl%". See Storing triggers in the depot for more information.

Examples

Example pre-rmt-Fetch command trigger

#!/bin/bash
# pre-rmt-Fetch trigger example
# Trigger table entry:
# prerfetch command pre-rmt-Fetch "pre-rmt-fetch.sh %serverid% %peerhost%"
serverid=$1
peerhost=$2
echo -e "Remote $peerhost is initiating a fetch of data from $serverid\n" | mail -s "Data is being fetched from $serverid to $peerhost" perforce-admin@localhost
exit 0

Trigger table entry

prerfetch command pre-rmt-Fetch "pre-rmt-fetch.sh %serverid% %peerhost%"

Example post-rmt-Fetch command trigger

#!/bin/bash
# post-rmt-Fetch trigger example
# Trigger table entry:
# postrfetch command post-rmt-Fetch "post-rmt-fetch.sh %serverid% %peerhost%"
serverid=$1
peerhost=$2
echo -e "Remote $peerhost has been fetching data from server $serverid\n" | mail -s "Data has been fetched by $peerhost from server $serverid" perforce-admin@localhost
exit 0

Trigger table entry

postrfetch command post-rmt-Fetch "post-rmt-fetch.sh %serverid% %peerhost%"

Example pre-rmt-Push command trigger:

#!/bin/bash
# pre-rmt-Push trigger example
# Trigger table entry:
# prerpush command pre-rmt-Push "pre-rmt-push.sh %serverid% %peerhost%"
serverid=$1
peerhost=$2
echo -e "Remote server $peerhost is initiating a push of  data to server $serverid\n" | mail -s "Data being pushed to server $serverid from $peerhost" perforce-admin@localhost
exit 0

Trigger table entry

prerpush command pre-rmt-Push "pre-rmt-push.sh %serverid% %peerhost%"

Example post-rmt-Push command trigger

#!/bin/bash
# post-rmt-Push trigger example
# Trigger table entry:
# postrpush command post-rmt-Push "post-rmt-push.sh %firstPushedChange% %lastPushedChange% %serverid%  %peerhost%"
firstchange=$1
lastchange=$2
serverid=$3
peerhost=$4
if [ $firstchange = 'unset' ]; then
echo -e "Remote server $peerhost attempted a push of data but there was nothing to push\n" | mail -s "Nothing to push from $peerhost" perforce-admin@localhost
else
echo -e "Remote server $peerhost has pushed data to $serverid,\nFirst change $firstchange, last change $lastchange" | mail -s "Data pushed to $serverid from $peerhost" perforce-admin@localhost
fi
exit 0

Trigger table entry

postrpush command post-rmt-Push "post-rmt-push.sh %firstPushedChange% %lastPushedChange% %serverid% %peerhost%"