The publish step needs to sync at job initial checkout changelist (or have a pin option).
The sync step will look for the latest changelist and sync to it. For example:
P4: found 170 revision in //jenkins-built-in-Case01443673_ReconcileOverwritesNewerChanges_Freestyle-1/...170 ...cut... P4 Task: syncing files at change: 170 ... p4 sync /var/lib/jenkins/workspace/Case01443673_ReconcileOverwritesNewerChanges_Freestyle/...@170
But a publish step always syncs at head:
sync -k //streams/main/ReconcileOverwrite/...
If a change has been submitted to the code between the sync and the publish step, the publish will overwrite the newer code.
Reproduction Steps:
(1) Create a stream.
(2) Create a Freestyle job that:
- syncs the stream
- has a sleep/wait step as a build step that sleeps for 60 second.
- publishes the full workspace
(3) Run the job.
(4) During the sleep/wait step in the job submit a change to the stream from the command line.
(5) After the job completes sync the latest version of the file changed in step (4). You will see that your changes have been reverted to the version of the file synced by the checkout step.
Possible solutions:
(1) Have a tickbox to disable the sync part of a publish step so it uses the have list for the checkout workspace.
(2) Have a 'pin' option for the publish step and surface a variable that is the changelist synced by the original checkout. WARNING - Pipeline jobs can have multiple checkout steps which overwrite the CHANGELIST variable.