How to Write a ClearCase Trigger That Sends Email Notifications

In this step-by-step guide, you’ll learn how to create a ClearCase trigger that sends email notifications whenever a specific event occurs, such as a file check-in.


Step 1: Define the Trigger’s Purpose

Decide on the SCM event you want to monitor. For this guide, we’ll create a trigger to send an email notification whenever a user checks in a file.


Step 2: Write the Trigger Script

ClearCase triggers execute a script or command when the trigger is activated. Here’s an example using a shell script:

Sample Script: send_email_trigger.sh

#!/bin/bash
# Trigger script to send email notifications on check-in

# Variables
EVENT_USER="$CLEARCASE_USER"        # User who triggered the event
ELEMENT="$CLEARCASE_PN"             # Path of the element being modified
OPERATION="$CLEARCASE_OP_KIND"      # Operation performed
TIMESTAMP=$(date)

# Email details
TO_ADDRESS="team@company.com"
SUBJECT="ClearCase Notification: Check-in by $EVENT_USER"
MESSAGE="User: $EVENT_USER
Action: $OPERATION
Element: $ELEMENT
Time: $TIMESTAMP"

# Send email (using the mail command)
echo "$MESSAGE" | mail -s "$SUBJECT" "$TO_ADDRESS"
  • Ensure the script has execute permissions:
    chmod +x send_email_trigger.sh
    

Step 3: Create the Trigger

Use the cleartool mktrtype command to create a trigger type associated with the desired event.

Example Command:

cleartool mktrtype -element -all -postop checkin \
  -exec "path/to/send_email_trigger.sh" email_on_checkin
  • -element: Specifies the trigger applies to elements.
  • -all: Applies to all VOBs.
  • -postop: Activates the trigger after the checkin operation.
  • email_on_checkin: The name of the trigger type.

Step 4: Apply the Trigger to VOBs

Attach the trigger to the desired VOB(s) to ensure it activates.

Command:

cleartool mktrigger email_on_checkin /vobs/my_vob

Step 5: Test the Trigger

To verify that the trigger works as expected, perform a check-in operation on an element within the VOB.

Example Test Command:

cleartool checkout -nc /vobs/my_vob/my_file.txt
cleartool checkin -nc /vobs/my_vob/my_file.txt
  • This will trigger the script and send an email notification.

Step 6: Review an Example Email Output

After testing, the email sent by the script should look like this:

Example Email:
Subject:
ClearCase Notification: Check-in by jdoe

Body:

User: jdoe  
Action: checkin  
Element: /vobs/my_vob/my_file.txt  
Time: Wed Jan 16 14:35:28 UTC 2025  

You can customize this message format in the script to meet your team’s needs.


Benefits of Using Email Notification Triggers

  • Improved Collaboration: Keeps the team informed about key actions.
  • Process Enforcement: Ensures compliance with your SCM policies.
  • Automation: Reduces manual communication efforts and errors.

Try implementing this trigger to make your ClearCase workflows more transparent and efficient!