Push-commit triggers
Use the push-commit
trigger type to create triggers that
fire after changelist creation, file transfer, and changelist commission
to the database. Use push-commit triggers for processes that assume (or
require) the successful push of a changelist.
Example
Following is a push-commit trigger that sends emails to other users who have files open in the pushed changelist.
#!/bin/sh # mailopens.sh - Notify users when open files are updated changelist=$1 workspace=$2 user=$3 p4 fstat @$changelist,@$changelist | while read line do # Parse out the name/value pair. name='echo $line | sed 's/[\. ]\+\([^ ]\+\) .\+/\1/'' value='echo $line | sed 's/[\. ]\+[^ ]\+ \(.\+\)/\1/'' if [ "$name" = "depotFile" ] then # Line is "... depotFile <depotFile>". Parse to get depotFile. depotfile=$value elif [ "'echo $name | cut -b-9'" = "otherOpen" -a \ "$name" != "otherOpen" ] then # Line is "... ... otherOpen[0-9]+ <otherUser@otherWorkspace>". # Parse to get otherUser and otherWorkspace. otheruser='echo $value | sed 's/\(.\+\)@.\+/\1/'' otherworkspace='echo $value | sed 's/.\+@\(.\+\)/\1/'' # Get email address of the other user from p4 user -o. othermail='p4 user -o $otheruser | grep Email: \ | grep -v \# | cut -b8-' # Mail other user that a file they have open has been updated mail -s "$depotfile was just submitted" $othermail <<EOM The Perforce file: $depotfile was just pushed in changelist $changelist by Perforce user $user from the $workspace workspace. You have been sent this message because you have this file open in the $otherworkspace workspace. EOM fi done exit 0Fo
To use the trigger, add the following line to your triggers table:
sample3 push-commit //... "mailopens.sh %change% %client% %user%"
Whenever a user pushes a changelist, any users with open files affected by that changelist receive an email notification.
The section Triggering before or after commands describes some additional options you have for triggers with push and fetch actions.