P4 Triggers - edit changelist description after submit on client - perforce

If I submit the changelist in P4V, I'd like to change the description of the changelist through the P4 trigger.
like this,
https://www.perforce.com/manuals/p4sag/Content/P4SAG/scripting.triggers.push.html
Command executed with change-submit(or change-commit) trigger but Description did not change.
p4 --field Description=DESCRIPTIONS... change -o CHANGELISTNUM | p4 change -i -u
I've tried p4 change options -i -u and -i -f, all option not working on trigger command.(script)
(In the environment where the trigger works, the -f option is possible because the superuser account is logged in.)
Has anyone changed the description through the trigger?
Thanks 🙏

Yes; it should work if you use -f. -u won't work unless the trigger is running as the user who owns the changelist (i.e. the user who's doing the submit), but -f will work as long as the trigger is running as an admin. If it's not working, double check your permissions.
Simple example:
C:\Perforce\test>p4 triggers -o
(...snip...)
Triggers:
update-desc change-commit //... "cmd /c p4 --field Description+=DESCRIPTIONS... change -o %change% | p4 change -if"
C:\Perforce\test>p4 submit -d "test description"
Submitting change 301.
Locking 1 files ...
edit //stream/main/foo#6
Change 301 submitted.
Change 301 updated.
C:\Perforce\test>p4 change -o 301
(...snip...)
Description:
test description
DESCRIPTIONS...
Triggers don't execute in a command shell, so if you want to use shell features like | redirection, you may need to explicitly use a command shell to process the command line (in my case cmd /c does that job).
Note the extra Change 301 updated in the submit output; that's the output of the trigger's p4 change -i being echoed back to the client. If your trigger isn't working, look carefully at the output that you're getting from the p4 submit, since it will probably contain an error message that gives you a clue where the trigger is failing. If you see the entire change spec being echoed back to you, that's a clue that the redirection isn't working. (If you can't find any trigger output in P4V, go do a test submit from the CLI; if you still can't find any, double check the triggers entry for typos, and the server log for errors.)
Note that change-submit is a pre-submit trigger, whereas change-commit is a post-submit trigger. If you want the trigger to fire after a successful submit, you want change-commit.

Related

How to change description of a pending (shelved) changelist using command?

I've created CL#100 with some description and shelved some files.
Now I need to edit the description of that CL using a command.
I have tried these 2 ways and both failed (same error msg)
p4 change -u 100 "Description: test description edit"
p4 change -o 100 > myDes.txt >> Edit Description field in myDes.txt >> p4 change -u 100 < myDes.txt
Error:
Execution Failed: "'C:
Program" "C:\Users\iman\AppData\Local\Temp\t26660t63.tmp": The system cannot find the file specified.
Client side operation(s) failed. Command aborted.
Edited File C:\Users\iman\AppData\Local\Temp\t26660t63.tmp kept due to errors.
It sounds like your P4EDITOR is set to "C:\Program", which is making p4 unable to launch an editor. This will cause problems for any command which edits a spec, not just p4 change commands! Do:
p4 set P4EDITOR=notepad
to set your editor to notepad (the default on Windows).
Then you should be able to run:
p4 change 100
The -u flag isn't needed for the update since this is a pending changelist (you can freely edit your pending changelists by default). The description is not specified on the command line; it's part of the spec that you'll edit in the editor.
If for some reason you need to do this without an editor (e.g. you're writing a script), you need to use -o to output to stdout and -i to input from stdin. I recommend using --field to modify the field instead of writing your own script to parse the changelist spec:
p4 --field "Description=test description edit" change -o 100 | p4 change -i

Perforce submit with revertunchanged option gives empty changelist

I have a PowerShell script for nightly tests which look something like:
# Check out the result file
p4 edit result.txt
# Run tests (which write into results.txt)
RunTests
# Submit results (but only if changed from last test run)
p4 submit -f revertunchanged -d "Results from nightly tests" results.txt
This works great, except from every time results.txt is unchanged. At those times an empty changelist is left after the script is finished.
Is there any way to avoid this empty changelist?
The empty changelist is no big deal; you can just delete it if you want.
But, you might instead change your script slightly: just before you do the submit, do 'p4 revert -a results.txt'. That will revert results.txt, but only if it is unchanged.
Only run the 'p4 submit' if the 'revert -a' did not revert result.txt, because that means you have actual changes in it. (Another way to check this is to run 'p4 opened results.txt' to see if 'revert -a' left it open or not.)

How to change the p4 submit description

I am new to Perforce. Here's the problem:
$ p4 submit
Change 9 created with 1 open file(s)
Submitting change 9.
Locking 1 files ...
Submit validation failed -- fix problems then use 'p4 submit -c 9'.
The problem is that the description that I entered into the submit form was bad. How do I change it?
I checked the docs for p4 submit, and didn't understand what -i does. Maybe that's what I need.
I tried:
$ p4 submit -i "Better description" -c 9 filename
and got:
Usage: submit [ -i -s -r ] [ -c changelist# ] [file]
Missing/wrong number of arguments
Thanks!
Even if the changelist is already submitted you can change the description with
p4 change -u 9
Since this is a pending changelist, and since it doesn't sound like you need to do this from a script, just do:
p4 change 9
This will bring up the changelist form in an editor so you can edit it. Make the edits, save the file, then exit the editor. Then do:
p4 submit -c 9
You may already know this, but the "validation failed" message means that your Perforce admin has some kind of custom trigger set up that blocked the submit -- the trigger could be doing literally anything, so if it keeps failing you may need to check with your admin to see what you're supposed to be doing (and whether the trigger is behaving correctly).
If you were editing the changelist form from a script you would use the "-i" flag as follows:
p4 change -o 9 | sed -e "s/magic/regex/" | p4 change -i
p4 submit -c 9
but obviously as an end user it's easier to just do "p4 change 9" and use the editor than to write a shell script to edit the description for you.
With a newer Perforce server you can specify the description during submit with:
p4 submit -d "Better description"
but since the "-d" flag isn't listed in your usage message I'm guessing you're using an old version.
in History tab, right click on your entry, "view changelist", then "edit", modify your description and "ok"

How can I change the description of a existing changelist in command line?

The command "p4 change" prompts a editor and needs a form. But I want to do this in command line.
How can I achieve this?
Use the following command:
p4 change -u CL_number
For details, please visit this page.
This command line worked for me:
p4 --field Description="New CL description here" change -o *changelist_number* | p4 change -i
There's always the -i command:
Read a changelist description from standard input. Input must be in the same format used by the p4 change form.
As Bryan points out in his comment the best approach is probably to run change -o, redirect the output to a file, process the file with other shell commands, and then send that file back to the server with change -i.
Source
But you can always change the description when you submit:
p4 submit -d "description"
This only works on the default change list.
Source

How to perform p4 submit operation without passing description inside the p4 submit form

I have a p4 client workspace on Linux machine.
I added/edited few files in my client space and then tried to submit those changes to perforce server.
I followed the steps below but could not succeed:
p4 submit -d "test" (the same command works on a Windows machine)
when I tried it with just p4 submit then it opened a p4 submit form and then I replaced [enter description here] token with the proper description and then it works.
But I don't want to edit the p4 submit form for every p4 submit task.
How can I pass this info in from the command prompt?
Answer
-d flag support for p4 submit command was not introduced in
perforce 2006 version. so here is the workaround for this problem:
To modify the description field on pre-2006.2 release Perforce Servers, try
piping the change form in/out of a stream editor. This will create a numbered
changelist, which should then be submitted.
For example, something like:
p4 change -o | sed -e "s/<enter description here>/my desc/" | p4 change -i
Which gives the output, similar to:
Change 102 created with 3 open file(s).
This change (number 102 in this case) can then be submitted, as follows:
p4 submit -c 102
It's not just the description you need to enter, you also can edit the changelist specification which allows you to exclude files from the commit.
If you can do it on windows then perhaps there is a newer client on windows than what you're using on Linux?
From http://www.perforce.com/perforce/downloads/platform.html download the appropriate version of p4 command-line client. Then:
Replace the existing p4 executable with the new one.
Or put the new p4 exe in a directory earlier in your $PATH
Make the chmod 755 <new p4>
hash -r
p4 -V to verify you are running perforce 2009.1 client
p4 help submit
We can md5sum the p4 binary
p4 info and verify the perforce server is 2006.2 or more recent.
Step 5 should produce:
$ p4 -V
Perforce - The Fast Software Configuration Management System.
Copyright 1995-2009 Perforce Software. All rights reserved.
Rev. P4/LINUX26X86/2009.1/205670 (2009/06/29).
Step 6 should produce:
$ p4 help submit
submit -- Submit open files to the depot
p4 submit [ -r -s -f option ]
p4 submit [ -r -s -f option ] files
p4 submit [ -r -f option ] -d description
p4 submit [ -r -f option ] -d description files
p4 submit [ -r -f option ] -c changelist#
p4 submit -i [ -r -s -f option ]
'p4 submit' commits a pending changelist and its files to the depot.
With no argument 'p4 submit' attempts to submit all files in the
'default' changelist. Submit provides the user with a dialog
similar to 'p4 change' so the user can compose a changelist
description. In this dialog the user is presented with the list
of files open in changelist 'default'. Files may be deleted from
this list but they cannot be added. (Use an open command (edit,
add, delete) to add additional files to a changelist.)
If a (single) file pattern is given, only those files in
the 'default' changelist that match the pattern will be submitted.
The -c flag submits the numbered pending changelist that has been
previously created with 'p4 change' or a failed 'p4 submit'.
The -d flag allows a description to be passed into submit rather
than using a numbered changelist or engaging in a change description
dialog. This option is useful when scripting but does not allow for
jobs to be added or the default changelist to be modified.
The -f flag allows a submit option to be passed into submit which
will override the one that is set in the client. See 'p4 help client'
for valid submit options.
The -i flag causes a changelist specification (including files to be
submitted) to be read from the standard input. The user's editor
is not invoked.
The -r flag allows submitted files to remain open (on the client's
default changelist) after the submit has completed.
The -s flag extends the list of jobs to include the fix status
for each job, which becomes the job's status when the changelist
is committed. See 'p4 help change' for more notes on this option.
Before committing a changelist submit locks all associated files not
already locked. If any file cannot be locked, or if the submit
fails for any other reason the files are left open in a newly
created pending changelist.
Submit is guaranteed to be atomic. Either all files will be
updated in the depot as a unit or none will be.
Of which the important bit is:
The -d flag allows a description to be passed into submit rather
than using a numbered changelist or engaging in a change description
dialog. This option is useful when scripting but does not allow for
jobs to be added or the default changelist to be modified.
Step 7:
$ md5sum $(which p4)
bef01f66b8d3964c74a2d8992c0c900c /opt/perforce/bin/p4
Step 8:
The feature was introduced in perforce 2006.2, and it's possible that it requires a sufficiently recent server to support the operation:
#106450 (Bug #258) **
'p4 submit' now sports a '-d description' option. This allows
the user to submit files without the need for a changelist
dialog. See 'p4 help submit'.

Resources