Triggering with depots of type graph

To associate the trigger with a single repo named //graphDepot1/repo8, specify the path as //graphDepot1/repo8/…​ with the /…​ wildcard at the end.

To associate the trigger with multiple repos, such as //graphDepot1/repoA and //graphDepot2/repoB, use asterisks (*) to specify //graphDepot*/repo*/…​ as the path, including with the /…​ wildcard at the end.

For information about depots of type graph, see Work with Git.

The following types of graph triggers are described in the order they would normally execute: graph-push-start, graph-push-reference, graph-push-reference-completegraph-push-complete

See also the Example of checking a commit

Trigger fields for graph depots

Field Meaning

name

The user-defined name of the trigger, such as graphpushstart

type

Type When it fires
graph-push-start Prior to data being transferred as part of a git push operation through Git Connector.
graph-push-reference When each reference is being created or updated through Git Connector or a p4 submit to a graph depot.
graph-push-reference-complete After a reference has been created or updated as part of a git push operation through Git Connector.
graph-push-complete When a git push of a specified repo has successfully completed.
graph-lfs-push Prior to any LFS files being transferred by a push from Git of a file being tracked as an LFS file.

path

A file pattern that matches the desired repos. The path ends with a wildcard (/...) even if only matching a single repo.

command

The trigger for Helix Core Server to run when the path is matched for a git push operation through the Git Connector or a p4 submit to a graph depot. For example,

graphpushstart graph-push-start //graph/repo1/... “/path/to/triggerscript.sh %depotName% %repoName% %repo% %pusher%”

where the command enclosed in quotation marks includes these variables:

Variables in the command field

Variable

Description

%depotName%
  • The graph depot in which the repo resides.
  • %repoName%
  • The name of the repo, such as //graphDepot1/repo8
  • %repo%
  • The repo, such as //graphDepot1/repo8.git which has .git as a suffix, but otherwise is identical to %repoName%.
  • %pusher%

    The user who caused the ‘push’, whether from a git-push operation through Git Connector or a p4 submit to a graph depot.

    graph-push-start

    • Fires prior to any data being transferred as part of a git push operation through the connector
    • Can enforce your workflow rules

    Trigger table entry

    graphpushstart graph-push-start //graph/repo1/... “/path/to/triggerscript.sh”

    graph-push-reference

    • Fires for each reference that is being created or updated
    • Can have logic to block the update, according to your workflow rules
    • If the trigger fails on any reference, the entire push is canceled

    A graph-push-reference trigger passes the original reference value in the %oldValue% variable, the new value in the %newValue% variable, and the reference name in %reference%.

    When such a trigger is fired from a push to the Git Connector:

    • the reference type is passed in the %refType% variable.
    • the %refFlags% variable is populated with a list of actions that are being applied to the reference.

    Trigger table entry

    graphpushref graph-push-reference //graph/repo1/... “/path/to/triggerscript.sh”

    graph-push-reference-complete

    • Fires after a reference has been created or updated as part of a git push operation through the Git Connector
    • Same variables as graph-push-reference
    • Any trigger failures are ignored

    Trigger table entry

    graphpushrefcomplete graph-push-reference-complete //graph/repo1/... “/path/to/triggerscript.sh”

    graph-push-complete

    • Fires when a git push of a specified repo has successfully completed
    • You can use this trigger to signal that all the files are present and ready for a build, testing, or diagnostic tool.

    Trigger table entry

    graphpushcomplete graph-push-complete //graph/repo1/... “/path/to/triggerscript.sh”

    graph-lfs-push

    • Fires prior to any LFS files being transferred.

    Trigger table entry

    graphlfspush graph-lfs-push //graph/repo1/... “/path/to/triggerscript.sh”

    Example of checking a commit

    Suppose that the use case for a trigger is to enforce a business rule such as the following:

    Your organization requires that all commits include a "Description" with a issue tracking number or BugIdNumber, such as P4-17870, or a Perforce Job Number, such as job097329.

    The trigger code might be as follows.

    #!/bin/bash
    reference=$1
    oldValue=$2
    newValue=$3
    refType=$4
    pusher=$5
    refFlags=$6

    logFile='/home/perforce/triggers/checkCommit.log'
    time=`date`
    echo "$time " >> $logFile
    echo "Depot: $depotName" >> $logFile
    echo "Repo: $repoName" >> $logFile
    echo "Reference: $reference" >> $logFile
    echo "oldValue: $oldValue" >> $logFile
    echo "newValue: $newValue" >> $logFile
    echo "refType: $refType" >> $logFile
    echo "Pusher: $pusher" >> $logFile
    echo "refFlags: $refFlags" >> $logFile
    echo "" >> $logFile
    requiredText="JIRA"
    p4 graph cat-file commit $newValue >> $logFile

    p4 graph cat-file commit $newValue | grep $requiredText >> $logFile
    res=`p4 graph cat-file commit $newValue | sed -n "/$requiredText/p"`
    if [ -n "$res" ] ; then
    echo "contains the $requiredText job number" >> $logFile
    exit 0
    else
    echo "NOT contains the $requiredText job number" >> $logFile

    exit 1
    fi

    To call the trigger:

    checkCommit graph-push-reference //repo/rtest/... "/home/perforce/triggers/checkCommit.sh %reference% %oldValue% %newValue% %refType% %pusher% %refFlags%"