[p4] Trigger User issue

Qazwart qazwart at gmail.com
Sat Feb 10 16:48:55 PST 2007


It's the thing that drives me most bonkers with Perforce: When a  
trigger fails, Perforce does not print out STDERR, so you don't see  
the error messages why something failed. In order to get around this  
problem, you should merge STDOUT and STDERR in your trigger definitions:

"c:\PerforceScripts\enforcejob.cmd %changelist% 2>&1"

This will allow you to see the mysterious missing error message as to  
why your trigger didn't run.

And one more issue while we're on this: Perforce believes that "p4"  
command only fail if they actually fail and not merely returned  
unexpected results. For example, if you did a "p4 files ./foo.c", and  
file foo.c doesn't exist, the "p4" command will still return an  
errorlevel of zero.

This means you have to be very careful with your trigger scripts  
because you cannot use the standard methods of determining if a  
command you executed really failed. My recommendation is to use one  
of the P4 libraries like P4Perl or P4Python and write your scripts in  
that language, or if you must, run the Perforce command with "p4 -s"  
and check if the first line of output starts with "error". You  
probably won't have this issue with this particular trigger, but you  
want to keep this in mind with future triggers.

As Robert has already pointed out, you seem to understand why you got  
this error, and setting "-u" in the Perforce command will solve this  
issue. Of course, that means going through your script and changing  
each occurrence of "p4" to "p4 -u <User>".

Another way of solving this is to set the registry on your server to  
automatically execute "p4" as the Perforce user. You can do that by  
"p4 -s P4USER=<p4User>". The service will still execute as the  
Service Account, but it will run the "p4" command as P4USER. This  
way, you don't have to modify your trigger scripts.

On Feb 9, 2007, at 5:27 PM, Ruy Diaz wrote:

> Hi everyone,
>
>
>
> I am having some trouble getting triggers to work properly on my  
> Windows
> 2000 Server box running Perforce 2006.2.
>
>
>
> I'm having trouble setting up a trigger that will fail a submit  
> when no jobs
> are appended. I have
>
> followed the examples in the documentation but I am still unable to  
> get it
> to work. I currently think It has something to do with user  
> permissions or
> something of the sort.
>
>
>
> My setup is as follows:
>
>
>
> Security level: 1
>
>
>
> Triggers:
>
>
>
>        MustHaveJob change-submit //depot/...
> "c:\PerforceScripts\enforcejob.cmd %changelist%"
>
>
>
> Protections:
>
>
>
>        write group developers * //...
>
>        super user Administrator * //...
>
>
>
> And my trigger script (enforcejob.cmd) is as follows:
>
>
>
> @echo off
>
> p4 describe -s %1 | findstr /c:"Jobs fixed"  nul
>
> if errorlevel 1 echo You must provide a job
>
> p4 describe -s %1 | findstr /c:"Jobs fixed"  nul
>
>
>
> If I run the script directly on the server from the commandline (e.g.
> enforcejob 26), it behaves correctly. However, when I try to submit a
> changelist from p4v in my client with a user from the developers  
> group, it
> always fails showing the following regardless of wether I have  
> attached a
> job or not:
>
>
>
> p4 submit -i
>
> Submit validation failed -- fix problems then use 'p4 submit -c 28'.
>
> 'MustHaveJob' validation failed: You must provide a job
>
>
>
>  I think the problem lies in what is being returned by 'p4  
> describe' to  the
> perforce server because I tried changing the script to:
>
>
>
>  p4 info
>
>  p4 describe
>
>
>
> And in the response, it looks like the describe is returning  
> nothing  at all
> (I removed echo off too):
>
>
>
> p4 submit -i
>
> Submit validation failed -- fix problems then use 'p4 submit -c 28'.
>
> 'MustHaveJob' validation failed:
>
> C:\Program Files\Perforce>p4 info
>
> User name: SYSTEM
>
> Client name: perforce1
>
> Client host: perforce1
>
> Client unknown.
>
> Current directory: c:\Program Files\Perforce
>
> Client address: 127.0.0.1:2771
>
> Server address: perforce1:1666
>
> Server root: C:\Program Files\Perforce
>
> Server date: 2007/02/08 11:34:14 -0800 Pacific Standard Time
>
> Server version: P4D/NTX86/2006.2/113956 (2007/01/04)
>
> Server license: MeZine 10 users (expires 2007/03/15)
>
> C:\Program Files\Perforce>p4 describe
>
>
>
> I tried adding a SYSTEM user (as this is the user that p4 info  
> shows when
> called from within a trigger) and obtained the same result. I also  
> tried
> giving the SYSTEM 'super' privileges through 'p4 protect' to no  
> avail. Is
> there a way to change this current user?
>
>
>
> I have tried providing a user and password with the p4 describe  
> command and
> this seems to work. However, I don't like the idea of having a  
> password in
> plaintext in the .bat file. Any workarounds? I have tried setting  
> P4USER and
> P4PASSWD using 'p4 set' but this also does not work, the SYSTEM  
> user is
> still used. I also tried executing 'p4 describe -u Administrator -s  
> %1' with
> no result.
>
>
>
>
>
> Any pointers on what I'm doing wrong?
>
>
>
> Thanks
>
> Ruy
>
>
>
> _______________________________________________
> perforce-user mailing list  -  perforce-user at perforce.com
> http://maillist.perforce.com/mailman/listinfo/perforce-user


More information about the perforce-user mailing list