Help with checkout directory and branches
Hi, I use teamcity to manage the CI of a game developed in Unreal. Because an Unreal game has hundreds of GB, I always use a common checkout directory to avoid having to re-download those GB or to be able to cache the compilation/shaders...etc.
I want to have support for branches, so I want each checkout depending on the branch to go to one directory or another.
The first thing I have thought is to use %teamcity.build.branch% in the Checkout Directory field. The problem is that I use PlasticSCM and the branches are /Main and /Main/BranchA. So when the directory is created, it creates a folder structure for me. The problem with this is that it creates Main folder and then inside BranchA.
Project
Project/Main
Project/Main/BranchA
It's not a good idea to have the directories nested and I even think Teamcity can cause the checkout directory to be cleaned up and that's something I want to avoid.
Another way I thought is to use a bootstrap step to do a replace of the branch and change “/” for “_”. Set an environment variable and that is the one I put in the checkout dir. But this doesn't seem to work, as the directory creates with the default variable value even before I modify this variable in the bootstrap.
I can't think of any more ideas and I don't know if there is anything I can do to get what I want.
Something like this:
Project_Main
Project_Main_BranchA/
Thanks, best regards
Javi
Please sign in to leave a comment.
The checkout happens before the build starts, so the directories are created with the default value as you described.
Here are a couple of things to consider:
1. You can explicitly set TeamCity to not clean up the checkout directory: https://www.jetbrains.com/help/teamcity/build-checkout-directory.html#Checkout+Directory+Expiration
You should use the `system.teamcity.build.checkoutDir.expireHours=never` build configuration property (https://www.jetbrains.com/help/teamcity/configuring-build-parameters.html).
Please note that the content of the checkout directory (even if the custom directory is used) can be deleted by TeamCity under certain circumstances (https://www.jetbrains.com/help/teamcity/clean-checkout.html#Automatic+Clean+Checkout).
2. You can disable the automatic checkout and then perform the checkout in the build step: https://www.jetbrains.com/help/teamcity/vcs-checkout-mode.html
Best regards,
Anton
Hi Anton,
Thanks for the response.
I didnt know about the
system.teamcity.build.checkoutDir.expireHours=never, thats super useful, thanks.I guess I will have to checkout manually then, I was trying to find something more automated, but that option works for me too.
Thanks,
Javi
Hi,
If I may, I thought something similar as what Javier did.
I thought the boostrap steps could be use to define the workspace to use, depending on some rules.
So just in case this can help push some flexibility, that would be nice.
Thanks.
Hi Alter,
Sorry, I am not familiar with Javier.
It sounds like you want to dynamically choose which workspace or directory to use based on certain rules, such as the branch name.
Yes, we can achieve this using Bootstrap Steps:TeamCity Bootstrap Steps.
Bootstrap steps are special build steps that run before the agent checks out the source code. They allow you to prepare the environment or workspace dynamically:
You can set the VCS checkout mode to "Do not checkout files automatically", and then implement your own logic in a bootstrap step. For example:
• Read the current branch using the %teamcity.build.branch% parameter
• Based on the branch name, define a specific checkout folder
• Use commands or scripts to perform a manual checkout into that directory
This gives you full control over the checkout location.
Best Regards,
Tom