Preventing Job Closure on Submit
Using a submit trigger to validate job status
PROBLEM
I would like to prevent jobs from being closed automatically when they are linked to a changelist being submitted.
SOLUTION
The following shell script example finds any jobs attached to a submitted changelist and reasserts the current job status. Jobs can still be closed with the p4 fix and p4 job commands.
- The trigger assumes that job identifiers are of the format "job[0-9]{6}". If your jobs have a different identifier format, you need to modify the script accordingly.
- The trigger assumes that your job spec has a "Status" field and that all possible status values are single words (no spaces).
- If you enter a changelist description that matches this pattern "^ job[0-9]{6} closed #", the script assumes that this is an attached job being closed and attempts to act on it. Although unlikely, you should be aware of the possibility.
#!/bin/sh # Suppresses the default behavior whereby jobs are automatically closed # if they are associated with a submitted change. # Set the path to p4, the port, user, and password if necessary. P4CMD="p4 -p -u -PYou also need to add this entry to the triggers table:" CHANGE=$1 # Step over all closing jobs in the changelist being submitted. for JOB in `$P4CMD change -o -s $CHANGE | \ grep -E "^ job[0-9]{6} closed #" | cut -d ' ' -f 1` do # Obtain the current status of the job and reassert it. STATUS=`$P4CMD job -o $JOB | \ grep -E "^Status: " | cut -d ' ' -f 2` $P4CMD fix -s $STATUS -c $CHANGE $JOB done exit 0
preventJobClosure change-submit //depot/... "preventJobClosure.sh %change%"Note:
This is an example only, and should be modified and tested thoroughly before being used in a production server.
