Perforce - modifying files
Hello there.
I'm looking for guidance on how to best safely modify files in a Perforce tree during build.
Currently I am doing:
- Check out file using p4 checkout
- modifying file
- use modified file ina build step
- run a p4 revert in a build step which is “always run”.
This _can_ fail if the server is interrupted (rebooted, crashes) before the revert, and then the next checkout of the same buld config will fail because there are opened files in the workspace.
Is there some different way? Like for example making the files writable and modifying them, but still somehow flag them as requiring a “force” sync next checkout?
Can we force TeamCity to recognize this error condition and revert any files before the sync? (I don't think so)
I don't want to add the “-f” flag to sync because the repo is large. Also it doesn't overwrite “opened” files.
Please sign in to leave a comment.
Hi Sweskman,
In your case, ensuring the Perforce server runs smoothly and efficiently is essential for maintaining a robust version control system. This not only prevents build disruptions but also fosters seamless collaboration among developers. Regular monitoring, effective workspace management, and minimizing unnecessary server load are key to keeping the server in optimal condition.
> Can we force TeamCity to recognize this error condition and revert any files before the sync? (I don't think so)
TeamCity does not natively handle Perforce workspace issues, such as files left open after a failed build, in an automated manner. You could try the following approach to achieve that.
Save the current modified state of the file before making changes by using p4 shelve. You can log it to a remote location and remove it after the build. Before making any modifications, check if a shelved file exists. If it does, run p4 unshelve to restore the previous state.
As mentioned earlier, the most important factor is ensuring your Perforce server remains stable.
Best Regards,
Tom