Jump to content


form-commit stream trigger does not expand %change%

form-commit stream trigger change

  • Please log in to reply
6 replies to this topic

#1 whyummi

whyummi

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 10 April 2020 - 02:39 PM

Hi,
I wanted to restrict visibility for a change made after stream creation/edit, so this stream change is not visible by unwanted users with 'p4 changes' command.

I used a 'form-commit stream' trigger to update the change type to restricted, however the %change% variable is not expanded at trigger. According to documentation %change% should be expanded for form-commit trigger.

Triger:
set_restricted_stream form-commit stream "J:\apps\triggers_batch\set_restricted_stream.bat %change%"

set_restricted_stream.bat:
CD /D J:\apps\triggers_batch
@SET P4PORT=****
@SET P4USER=****
@SET P4PASSWD=****
@SET P4CLIENT=****
p4 change -t restricted -f %1

Error returned at stream creation/modification:
'set_restricted_stream' validation failed:
F:\P42\Server>CD /D J:\apps\triggers_batch

J:\apps\triggers_batch>p4 change -t restricted -f %change%
Invalid changelist number '%change%'.

As you see %change% is not expanded. Other variables i.e. %client% works fine.

Perforce server is running on Windows:
Server version: P4D/NTX64/2019.2/1897966 (2019/12/16)

Any suggestions, help what could be wrong? Is there a better way to do it?

#2 Sambwise

Sambwise

    Advanced Member

  • Members
  • PipPipPip
  • 1192 posts

Posted 10 April 2020 - 03:18 PM

The form-commit trigger fires only when the form is committed, not for every changelist submitted thereafter.  There's no %change% value because there is no changelist involved in firing the trigger.

What you want is a change-commit trigger (which fires on every changelist commit).  I think you can use your exact same trigger script; just set it up like:

set_restricted_change change-commit //... "J:\apps\triggers_batch\set_restricted_stream.bat %change%"

This will make every change restricted!  If you want to scope it to a particular depot path, change the "//..." to that path.

If you have some more particular definition in mind ("a change made after stream creation/edit"), you'll need to think about how exactly to define that.  (Every change?  Just the first change in a stream?  Just the first change after an edit to the stream spec?  ANY edit or just certain kinds?  What if it's much later; does that window ever close?)  I'm not clear on what your use case is so I don't have any suggestions, but you'll need to be able to define it in such a way that it can be interpreted by a script.

#3 whyummi

whyummi

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 14 April 2020 - 08:31 AM

I've already defined 'change-commit' type trigger just as you suggested above (the same syntax you typed), but it doesn't work for stream spec creation/change.

The goal is to hide the stream spec changes from 'p4 changes' for unwanted users (users not in a project). We work with several projects at a time, all on one Perforce server, different depots. We have also outsourcing contractors working in some projects. Because of the security we don't want to allow users who are not in the project, to view changes made on server, this includes stream names. Even in SWARM in 'commits' page you can view all changes made on server (when the change is not restricted). This also includes changes made in stream specs. We already hide the submits with 'change-commit' trigger but it is not triggered for stream spec change.

Example from p4 python api, after doing change in '//sandbox_streams/visibility_test' stream spec, with change-commit trigger on:

p4.run_changes("-m",10, "-l")
[
	{
		"change": "172898",
		"time": "1586852308",
		"user": "robot.obibok",
		"client": "robot.obibok_idk300_DEV",
		"status": "submitted",
		"changeType": "public",
		"path": "//sandbox_streams/visibility_test/*",
		"stream": "//sandbox_streams/visibility_test",
		"streamStatus": "streamSubmitted",
		"desc": "Stream //sandbox_streams/visibility_test saved."
	},
	{
		"change": "172897",
		"time": "1586850784",
		"user": "robot.obibok",
		"client": "****",
		"status": "submitted",
		"changeType": "restricted",
		"path": "****",
		"desc": "****"
	}
...
]


#4 Sambwise

Sambwise

    Advanced Member

  • Members
  • PipPipPip
  • 1192 posts

Posted 14 April 2020 - 03:21 PM

The streamStatus stuff isn't familiar to me -- I assume it's a byproduct of some new submit workflow?  If so it seems like it has a bug where it doesn't fire change-commit triggers; you should get a change-commit fire for every submitted changelist (even if it's from a command like "populate" where there's no actual submit, you'll still get a "commit" trigger event).  

The workaround would probably be to run a poll on "p4 changes" output after the fact (similar to how you're doing in your example) instead of relying on the trigger.

#5 whyummi

whyummi

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 15 April 2020 - 02:02 PM

The workaround I used, set a 'form-commit stream' trigger to execute little script which is setting restricted for all public changes made since last 60 seconds. Works ok.

View PostSambwise, on 14 April 2020 - 03:21 PM, said:

The streamStatus stuff isn't familiar to me -- I assume it's a byproduct of some new submit workflow?  If so it seems like it has a bug where it doesn't fire change-commit triggers; you should get a change-commit fire for every submitted changelist (even if it's from a command like "populate" where there's no actual submit, you'll still get a "commit" trigger event).  

Where can I report such bug?

#6 Sambwise

Sambwise

    Advanced Member

  • Members
  • PipPipPip
  • 1192 posts

Posted 15 April 2020 - 02:26 PM

View Postwhyummi, on 15 April 2020 - 02:02 PM, said:

Where can I report such bug?

https://www.perforce...request-support

#7 whyummi

whyummi

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 17 April 2020 - 06:35 AM

I got an update and conclusion to my problem.

So I contacted Perforce support regarding 'change-commit' trigger not fired on stream spec changes. It turns out the problem is only when I create/edit the virtual stream spec in p4v. When I manually use 'p4 stream edit' followed by 'p4 submit' the trigger is fired. However, p4v uses `p4 stream -i -t virtual` command to update the spec. In such case the 'change-commit' trigger is not fired, but a new change is submitted. The explanation for this behavior from support:

Quote

Hi Piotr,

I think I now understand what is happening.

You cannot checkout a virtual stream as it is an alternate view of its parent. If you try to checkout a virtual stream by command line, the parent non virtual stream will be checked out.

This is why your version of P4V include this fix:
Bugs fixed in  2019.2/1856742
#99642 (Change #1845768)
Checking out a virtual or task stream spec is not supported, so P4V will no
longer show the incorrect context menus Check Out and Check Out and Edit.
So that explains why your trigger does not seem to work as the virtual stream has never been checked out in the first place.

Unfortunately you will have to keep your workaround in place.

To sum up, to catch all stream spec changes I've used 'form-commit stream' trigger and a little script which is executed without %change% argument:

set_restricted_stream form-commit stream "J:\apps\triggers_batch\set_restricted_stream.bat"

Script looks for all public changes made in the last 60 seconds and if found, set restricted flag.





Also tagged with one or more of these keywords: form-commit, stream, trigger, change

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users