ISSUE :
 
Profile photo
Submitted by Sam Buchana
on November 1st, 2012 at 14:15:38 EST

Enforce Perforce job linking during submission to changelist

We are using Perforce for our source control. Now we wanted to enforce linking Perforce job during submission. Is there any default way to enforce "link jobs to changelist" in Perforce? Actually we wanted every check-ins to be associated with Perforce Job.


Profile photo
Replied by SBajra
on November 1st, 2012 at 14:28:24 EST
Here are some of the examples:
http://public.perforce.com/wiki/Pre-Submit_Trigger_Examples

But if you want the script in MS DOS Batch file version (.bat) then here is my solution. Its very simple and straightforward. I am passing changelist number to Perforce trigger and then using P4 fixes to check job information.


@ECHO off

SETLOCAL

IF x%1==x GOTO NOPARAM

SET changeListNumber=%~1
SET isJobAttached=0

FOR /F "tokens=1 delims=" %%A in ('p4 fixes -c %changeListNumber%') do (
SET isJobAttached=1
)

IF not %isJobAttached%==1 GOTO NOJOB

rem - Success
ECHO Jobs found
GOTO END


:NOPARAM
rem - No changelist number being passed
ECHO No Perforce ChangeList number being passed
EXIT 1
GOTO END

:NOJOB
rem - No Job Attached
ECHO Submissions must be associated with a job
EXIT 1
GOTO END

:END

ENDLOCAL


Save the script above to .bat file for example: checkjob.bat and then add this batch script to Perforce Triggers submit list:

To update Perforce triggers, execute following command:

p4 triggers


Then add following trigger with %changelist% as parameter

checkjob change-submit //depot/... "checkjob.bat %changelist%"


More information on Perforce triggers:
http://www.perforce.com/perforce/r12.1/manuals/cmdref/triggers.html
Accepted Answer
Accepted
 Answer