Example triggers

The following examples show you sample triggers that you can use to optimize your version control workflows.

Backup trigger

Create a trigger that fires after setting a workspace selector, located at /home/scripts/plastic-backup at the server, and give it the name backup:

cm trigger create after-setselector backup /home/scripts/plastic-backup

Validation triggers

Label validation

Create a trigger called that fires before a label is created, that calls validate-label.bat at server myserver on port 8084:

cm trigger create before-mklabel "Validate label" "c:\tmp\triggers\validate-label.bat" --server=myserver:8084

Create a trigger that fires before a label is created in repository default and that label starts with bl or fix:

cm trigger create before-mklabel "label-bl-fix" "c:\tmp\triggers\label-bl-fix.bat" --filter="rep:default,bl*,fix*"

Check in validation

Create a trigger that validates check in contents before the check in is actually performed in the repository, on a Windows server:

cm trigger create before-checkin ensure-code-stds "c:\plastic\triggers\checkcode.bat"

Web trigger notifications

URI notification

Create a web trigger that fires after a check in action is performed, at URI https://www.mysite.com/api/team/checkin and name it Notify team:

cm trigger create after-checkin "Notify team" "webtrigger https://www.mysite.com/api/team/checkin"

A request body example of that web trigger would be as follows:

{
 "PLASTIC_CHANGESET": "cs:2341@br:/main/task4638@rep:product@repserver:plastic.mysite.com:17590",
 "PLASTIC_CLIENTMACHINE": "DEV1HOST",
 "PLASTIC_COMMENT": "Fixing command line parsing",
 "PLASTIC_SERVER": "plastic.mysite.com:17590",
 "PLASTIC_SHELVE": false,
 "PLASTIC_USER": "dev1",
 "INPUT": [ "CH \"/src/main.c\" FILE" ]
}

Discord notification

Create a web trigger that fires after a check in and send notifications from the server to the specified Discord channel:

cm trigger create after-checkin NotifyTeam "webtrigger-discord https://discordapp.com/api/webhooks/811172464004562954/VNKRQ9JvPyvku0yYJg-hFmSesEePRFaMbikRlfkJBrb22QxmJoJVBmZR6iOWpiMIsS4t" --server=localhost:18084

Slack notification

Create a web trigger that fires after a check in and send notifications from the server to the specified Slack channel:

cm trigger create after-checkin SlackWebTrigger "webtrigger-slack https://slack.com/api/chat.postMessage/U01PW9EET5E/xoxb-1781717825334-1781730759222-34UxkCu8WmA2FlzzjTS6tRYy" --server=localhost:18084