# FinalBuilder and Perforce

**URL:** https://www.finalbuilder.com/forums/t/finalbuilder-and-perforce/480
**Category:** Discussion
**Created:** [May 31, 2007, 1:13am UTC](https://www.finalbuilder.com/forums/t/finalbuilder-and-perforce/480 "2007-05-31T01:13:45Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [May 31, 2007, 1:13am UTC](https://www.finalbuilder.com/forums/t/finalbuilder-and-perforce/480/1 "2007-05-31T01:13:45Z")

</div>

Hi All

Well I have recently moved from SVN to Perforce, and I am looking for similar bindings to:

IF[%Last\_SVN\_REVISION%]\<\>[%PREV\_SVN\_REVISION%]

Set Variable PREV\_SVN\_REVISION to [%Last\_SVN\_REVISION%]

&nbsp;

I am not sure how to achieve this with Perforce as my CM.

&nbsp;

Any ideas?&nbsp;

---

<div class="post-metadata">

### Author: ![angus](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/a/b3f665/32.png) [@angus](https://www.finalbuilder.com/forums/u/angus)
#### Post date: [May 31, 2007, 2:41am UTC](https://www.finalbuilder.com/forums/t/finalbuilder-and-perforce/480/2 "2007-05-31T02:41:18Z")

</div>

Hi Ronan,   
  
 I’m assuming that you were using the Subversion Info command to read the current repository revision to LAST\_SVN\_REVISION?   
  
 As you’ve no doubt noticed, Perforce is a bit different because it doesn’t keep a global revision which is the same for every file. However, it does keep a folder revision which is updated whenever folder contents change, so the Folder Revision for //depot should be roughly equivalent.   
  
 Unfortunately, I can’t seem to find a p4.exe command (via Perforce Generic action) which outputs a folder history and/or revision. If you can find one, then you can parse the output using the OnStatusMessage event and set the last revision number that way. Let me know if you find a command, and I can suggest some script which may work for you.   
  
 Sorry I can’t be of more assistance.   
  
 Regards,   
  
 Angus

---

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [May 31, 2007, 7:15am UTC](https://www.finalbuilder.com/forums/t/finalbuilder-and-perforce/480/3 "2007-05-31T07:15:30Z")

</div>

Sent off a support request to perforce, here is their response:

&nbsp;

You can changelist numbers here as your revision history guides.&nbsp; You can run  
the "p4 changes -m1 //path..." against the path that you are wanting to build.   
For example:  
  
&nbsp;&nbsp; p4 changes -m1 //depot/jphoto-0.3.6-src/...  
  
Where "//depot/jphoto-0.3.6-src/..." is the location of the area that you are  
monitoring in your build.  
  
This will give you an output similar to the following:  
  
&nbsp;&nbsp; Change 317 on 2007/04/17 by [timo@macbook](mailto:timo@macbook) 'updated USB interface'  
  
Here you can see that it is change "317" was the last change made to files  
beneath this depot path.&nbsp; As a result I can use this as the starting point of  
the revision history.&nbsp; If I run the above command at a later date, and the  
change returned is different, then I know I have to rebuild etc.  
  
The other useful thing about this approach is that you can include the change  
number within your build process.&nbsp; Take the Perforce Server for example:  
  
&nbsp;&nbsp;&nbsp; Server version: XXXXXXXXXXXXXXXXXXXXX/113956   
  
The "113956" part of the version string is actually the last changelist of the  
codepath that this server was built with.&nbsp; It means that just by including this  
I know what code was used to build the server and using it, if needed, I can  
make my workspace reflect this by running:  
  
&nbsp;&nbsp; p4 sync //...@113956

&nbsp;

&nbsp;

So I am going to try and get this working now.

Cheers

&nbsp;

[Edit]

&nbsp;

Hmmmm not as easy as I had hoped, I went down the route of using:

p4 changes -m1 //depot/jphoto-0.3.6-src/...

which obviously seems like the easiest way to interact. Any ideas on how to call this command using a script or similar?

&nbsp;

&nbsp;Cheers

&nbsp;

---

<div class="post-metadata">

### Author: ![angus](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/a/b3f665/32.png) [@angus](https://www.finalbuilder.com/forums/u/angus)
#### Post date: [May 31, 2007, 8:20am UTC](https://www.finalbuilder.com/forums/t/finalbuilder-and-perforce/480/4 "2007-05-31T08:20:11Z")

</div>

Hi Ronan,   
  
 You can use the ‘Perforce Generic’ action to run the ‘changes’ command with the required parameters. Use the ‘OnStatusMessage’ event to parse the output and extract the number.   
  
 Let me know if you’d like me to mock up a project for you.   
  
 Regards,   
  
 Angus

---

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [June 1, 2007, 5:53am UTC](https://www.finalbuilder.com/forums/t/finalbuilder-and-perforce/480/5 "2007-06-01T05:53:53Z")

</div>

I was looking through the help files, but couldn't find anything on:

OnStatusEvent

&nbsp;

and how to use the events?

---

<div class="post-metadata">

### Author: ![tate](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/t/e19b73/32.png) [@tate](https://www.finalbuilder.com/forums/u/tate)
#### Post date: [June 1, 2007, 6:20am UTC](https://www.finalbuilder.com/forums/t/finalbuilder-and-perforce/480/6 "2007-06-01T06:20:27Z")

</div>

Hi Ronan,   
  
 There is some help on script events in the section “Action Script Events”, the online version is here:   
 [https://www.finalbuilder.com/finalbuilder/Help/HTML/actionscriptevents.htm](https://www.finalbuilder.com/finalbuilder/Help/HTML/actionscriptevents.htm)   
  
 hth.   
 .t8

---

<div class="post-metadata">

### Author: ![Vincent](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/vincent/32/938_2.png) [@Vincent](https://www.finalbuilder.com/forums/u/Vincent)
#### Post date: [June 1, 2007, 8:17am UTC](https://www.finalbuilder.com/forums/t/finalbuilder-and-perforce/480/7 "2007-06-01T08:17:24Z")

</div>

Hi Ronan   
  
 The OnStatusMessage script event can be called muliple times, depending on how much output is captured from the executable being called. The statusmessage parameter is an object, which may contain multiple lines. You can check StatusMessage.Lines.Count to see how many lines there are, if there are more than 1 then use StatusMessage.Lines.Strings(index) to access each line, where index is 0 based. You should be able to use some VBScript or JavaScript to extract the change number from the output of P4. You can also use FinalBuilder variables in VBScript and JavaScript, either via the FBVariables object (in which case code completion will show you which variables are available) or just treat them as global variables in your script.   
  
 HTH

---

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [June 4, 2007, 2:14am UTC](https://www.finalbuilder.com/forums/t/finalbuilder-and-perforce/480/8 "2007-06-04T02:14:10Z")

</div>

Cheers   
  
The main issue I am having now (writing the script)   
  
Basically the line I am getting back is:   
  
Change 10110 on 2007/06/04 by ronanhayes@MW-RONANHAYES '#103281 - Tools.fbz5 Updated'   
  
So it's a matter now of pulling out the correct version number which I would assume is:   
  
#103281   
  
as:   
  
10110 is now the the changelist number. I could be wrong. So I simply need to extract the correct values from this line to save as a variable so I can compare with previous.   
  
I'm not much up on VBScript and Java Script has been some time. Hopefully I can get it sorted, any extra help would be appreciated.   
  
Cheers

&nbsp;

[edit]

var s = "Change 10110 on 2007/06/04 by ronanhayes@MW-RONANHAYES '#103281 - Tools.fbz5 Updated'";  
var m = s.match(/#\d+/);  
alert(m);

&nbsp;

Right all I need do now is:

&nbsp;

var s = StatusMessage.Lines.Text

&nbsp;

instead of an alert I just need to parse the text to a variable.

&nbsp;

Any ideas? I'll keep going at it.

&nbsp;

&nbsp;

---

<div class="post-metadata">

### Author: ![angus](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/a/b3f665/32.png) [@angus](https://www.finalbuilder.com/forums/u/angus)
#### Post date: [June 4, 2007, 2:26am UTC](https://www.finalbuilder.com/forums/t/finalbuilder-and-perforce/480/9 "2007-06-04T02:26:48Z")

</div>

Hi Ronan,   
  
Here's a simple solution in JScript which just extracts the first number preceded by a #. That should be robust enough to handle changes (ie I don't think every checkin has a changeset number, but I could be wrong...)   
  
If you'd like a solution which matches the ChangeSet number as well, this can be arranged.

&nbsp;

var line =&nbsp; "Change 10110 on 2007/06/04 by ronanhayes@MW-RONANHAYES '#103281 - Tools.fbz5 Updated'";  
var regexp = /#(\d+)\w/;  
  
var matches = regexp.exec(line);  
if (matches == null)  
{  
&nbsp;&nbsp; throw "Failed to match changeset string on line : " + line;  
}  
  
var RevisionNo = matches[1] ;  
Action.SendLogMessage("Folder revision " + RevisionNo);

&nbsp;

- Angus

---

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [June 4, 2007, 2:52am UTC](https://www.finalbuilder.com/forums/t/finalbuilder-and-perforce/480/10 "2007-06-04T02:52:10Z")

</div>

Hopefully one final thing, with

&nbsp;

var line =

&nbsp;

What should I be using in there when I want to take the the line returned by the Perforce Generic is it:

StatusMessage.Lines.Strings(0);

&nbsp;

?

---

<div class="post-metadata">

### Author: ![angus](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/a/b3f665/32.png) [@angus](https://www.finalbuilder.com/forums/u/angus)
#### Post date: [June 4, 2007, 3:02am UTC](https://www.finalbuilder.com/forums/t/finalbuilder-and-perforce/480/11 "2007-06-04T03:02:06Z")

</div>

Hi Ronan,   
  
 That should work fine, as long as the command always puts the output on the first line (which I think it does.)   
  
 Regards,   
  
 Angus

---

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [June 5, 2007, 7:40am UTC](https://www.finalbuilder.com/forums/t/finalbuilder-and-perforce/480/12 "2007-06-05T07:40:10Z")

</div>

Regarding variables how do I set them.   
  
 Is it via   
  
 Action.LogToVariable?   
  
 or is there an easier way to parse?

---

<div class="post-metadata">

### Author: ![angus](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/a/b3f665/32.png) [@angus](https://www.finalbuilder.com/forums/u/angus)
#### Post date: [June 5, 2007, 7:50am UTC](https://www.finalbuilder.com/forums/t/finalbuilder-and-perforce/480/13 "2007-06-05T07:50:45Z")

</div>

Hi Ronan,   
  
 You can just set variables as if they were local variables in the script, ie   
  
 VarName=VarValue;   
  
 … or you can use the FBVariables object, ie   
  
 FBVariables.VarName = VarValue;   
  
 (The FBVariables object gives you the advantage of code completion to show you the available names.)   
  
 - Angus

---

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [June 5, 2007, 8:12am UTC](https://www.finalbuilder.com/forums/t/finalbuilder-and-perforce/480/14 "2007-06-05T08:12:29Z")

</div>

Cheers, that’s pretty much done it, just a issue getting the result from the Perforce Generic :   
  
 StatusMessage.Lines.Strings(0);   
  
 Is throwing an exception, from what I can gather StatusMessage.Lines.Strings(0) is often null due to the number of Status Messages that occur.   
  
 Even if I ignore the null VS2005 still prompts for the Exception. It’s somethign silly at this point

---

<div class="post-metadata">

### Author: ![angus](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/a/b3f665/32.png) [@angus](https://www.finalbuilder.com/forums/u/angus)
#### Post date: [June 5, 2007, 8:26am UTC](https://www.finalbuilder.com/forums/t/finalbuilder-and-perforce/480/15 "2007-06-05T08:26:27Z")

</div>

Hi Ronan,   
  
 Try the property StatusMessage.MessageText . That should never be null.   
  
 Regards,   
  
 Angus

---

<div class="post-metadata">

### Author: ![angus](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/a/b3f665/32.png) [@angus](https://www.finalbuilder.com/forums/u/angus)
#### Post date: [June 5, 2007, 8:27am UTC](https://www.finalbuilder.com/forums/t/finalbuilder-and-perforce/480/16 "2007-06-05T08:27:58Z")

</div>

Also, if the action sometimes output other messages (Apart from the one you want to test), remove the line   
  
 throw "Failed to match changeset string on line : " + line;   
  
 and replace it with just   
  
 return;   
  
 (this will ignore any lines which don’t match the change number, but it won’t tell you if it couldn’t find the change number.)   
  
 - Angus

---

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [June 6, 2007, 12:56pm UTC](https://www.finalbuilder.com/forums/t/finalbuilder-and-perforce/480/17 "2007-06-06T12:56:15Z")

</div>

I had adjusted the if statement to simply ignore the nulls

&nbsp;

That said:

&nbsp;

FBVariables.Last\_Perforce\_Revision = "2";

&nbsp;

Doesn't seem to like being set. It's a tad strange but it throws and unknown exception.

---

<div class="post-metadata">

### Author: ![angus](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/a/b3f665/32.png) [@angus](https://www.finalbuilder.com/forums/u/angus)
#### Post date: [June 6, 2007, 2:33am UTC](https://www.finalbuilder.com/forums/t/finalbuilder-and-perforce/480/18 "2007-06-06T02:33:11Z")

</div>

Hi Ronan,   
  
 That looks like it should be OK. If you remove the FBVariables. notation, does it set the correct variable then?   
  
 If it’s still not working, could you please send us the project (support at finalbuilder dot com), and we’ll take a look at it. Thanks.   
  
 - Angus

---

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [June 6, 2007, 2:49am UTC](https://www.finalbuilder.com/forums/t/finalbuilder-and-perforce/480/19 "2007-06-06T02:49:07Z")

</div>

It appears to have worked nicely, I will email the project if it fails building.   
  
 Thanks for all the help.   
  
 Ronan
