1

I am trying to find source of integration from one of my opened file on my perforce client.

My command :-

/grid/common/pkgs/perforce/v2018.1/bin/p4 -p 10.202.176.19:1641 -Ztag -F %clientFile% opened -c default -C cheruvu_client | /grid/common/pkgs/perforce/v2018.1/bin/p4 -p 10.202.176.19:1641 -F %fromFile% -x - resolved

Command working as expected when i run it explicitly.

But when i try to run in my script it's not working as expected.

My script :-

use strict;
use warnings;
my $Client = $ARGV[0];
my $ChangeNum = $ARGV[1];
my $Port = $ARGV[2];
my $p4 = "/grid/common/pkgs/perforce/v2018.1/bin/p4 -p $Port";
my @files = `$p4 -Ztag -F %clientFile% opened -c $ChangeNum -C $Client | $p4 -F %fromFile% -x - resolved`;
if (@files){
 foreach my $file(@files){
 chomp($file);
 if ($file =~ /\/\/depot\/vip\/src\/branches\/private_branch\/.*/i){
   print "Integrations from private_branch-> main is not allowed.\n\n";
  exit(1);
 }
 }
 }

@files array value is empty. Though i have opened file for integrate.

Purpose my script is to setup a trigger to avoid integrations from private_branch to main branch. Not sure is something is wrong in my command mentioned in script.

Run time arguments to script is passed while submitting file. There is no issue in run time argument parsing.

Please help.

santosh
  • 421
  • 1
  • 6
  • 14
  • Is the command line correctly passed to the shell? Check the output you get if you insert `echo` in front of the command and remove/backslash escape the pipe – Håkon Hægland Jul 10 '19 at 12:18
  • Yes, I can see the command is passing correctly and able to run successfully.Command :- /grid/common/pkgs/perforce/v2018.1/bin/p4 -p 10.202.176.19:1641 -Ztag -F %clientFile% opened -c 953172 -C cheruvu_client | /grid/common/pkgs/perforce/v2018.1/bin/p4 -p 10.202.176.19:1641 -F %fromFile% -x - resolved – santosh Jul 10 '19 at 13:18
  • Ok, good! Now, I see that you use `$file` (scalar) instead of `@file` (array) in the `if` statement. Can that be the problem? – Håkon Hægland Jul 10 '19 at 13:38
  • No, That wont be any problem. Seem like i didn't copied foreach loop line. Now i corrected the script. – santosh Jul 10 '19 at 14:00
  • Ok try to gradually build up the command line. What happens if you just run the simple `$p4 -V` for example. Do you get output then? – Håkon Hægland Jul 10 '19 at 14:04
  • It shows copyright message of perforce. – santosh Jul 10 '19 at 14:11
  • Good, keep adding more and more to the command line until it does not give output – Håkon Hægland Jul 10 '19 at 14:12
  • it seems to be script issue. Not related to perforce In my opinion. – santosh Jul 10 '19 at 14:17

1 Answers1

2

The commands you're running are getting an error message somewhere and the -F arguments you've passed are stripping it out:

my @files = `$p4 -Ztag -F %clientFile% opened -c $ChangeNum -C $Client | $p4 -F %fromFile% -x - resolved`;

Replace this with:

open(STDERR, ">&STDOUT");
my @files = `$p4 -Ztag -F %clientFile% opened -c $ChangeNum -C $Client | $p4 -x - resolved`;
print @files;

to find out what error message you're getting.

If that's empty too, back up a step:

open(STDERR, ">&STDOUT");
my @files = `$p4 -Ztag opened -c $ChangeNum -C $Client`;
print @files;

Once you can see the error message, it will tell you what's wrong with the way you're calling the command.

My hunch is that the problem is that your resolved command isn't using the same client that the files are opened on. If that's the case, the error will be something like no file(s) resolved; you can confirm by passing the filename to p4 opened (without specifying -C client) to see if it's open on the current client.

Samwise
  • 68,105
  • 3
  • 30
  • 44
  • Hi Sam, I have replaced your first method above. I am hitting weird error : Client 'p4server11' unknown - use 'client' command to create it. Not sure why the client name is taking as 'p4server11' :( . Same command (without %fromFile%) if i run explicitly it works fine. Does perforce triggers run on master machine of perforce or it will run locally where we are trying to submit the file? – santosh Jul 11 '19 at 03:13
  • Triggers run on the server. You should not make any assumptions about the environment variables in a trigger script, and explicitly set them within the trigger. – Samwise Jul 11 '19 at 05:02