Create your first trigger

This page shows a workflow for how to create and edit a trigger that validates your label names through the command line:

  1. View available triggers.
  2. Create the trigger.
  3. View a list of your existing triggers.
  4. Edit the trigger.
  5. Delete the trigger.

View trigger types

To associate a user script with a client or server event, you need to create a trigger. To show a list of all supported trigger types in your command line, you can use the showtypes command:

cm trigger showtypes

Create a trigger

If your label names are created according to a given naming standard, you can create a trigger that validates label names. To create this trigger on Windows, you can use the following create command:

cm trigger create before-mklabel "check label name" "ruby c:\plastic\triggers\validate-label.rb"

This is a sample Ruby script (validate-label.rb) that checks that the label name starts with release:

if (ENV['PLASTIC_LABEL_NAME'] !~ /^release/) then exit(1) end

The script picks the name of the label from the PLASTIC_LABEL_NAME environment variable and checks the contents against the regular expression ^release, which matches a string that starts with release. If the label name doesn't match release (!~ operator), the trigger returns the exit code 1, which means the trigger fails and doesn't allow the mklabel operation to finish.

List triggers

To see any triggers that you create, you can use the list command to show all the triggers of the same type you created:

>cm trigger list before-mklabel
1 Validate label  c:\tmp\triggers\validate-label.bat dave

Edit triggers

To modify the script that this trigger is pointing to, you can use the trigger edit command. You need to indicate the trigger type and the trigger position, which is the first index that the list triggers command returns (1 in this case):

cm trigger edit before-mklabel 1 --script="c:\tmp\other-script.bat"

Delete triggers

To remove a trigger, you can use the trigger delete. You need to indicate the trigger type and position:

cm trigger delete before-mklabel 1