Reusing checkout out Perforce sources on AWS cloud agent

I am using Perforce and trying to set up cloud agents in AWS to reuse checked out sources as described here: https://www.jetbrains.com/help/teamcity/perforce-workspace-handling-in-teamcity.html#Reuse+Checked+Out+Sources+on+Cloud+Agents, but I'm not able to get the build to use the files that I have already checked out.

Here's my setup:

  • I have an AMI with a root volume snapshot that has Windows, a BuildAgent, and all of the tools I need to do a build.
  • The BuildAgent's work directory is C:\BuildAgent\work.
  • I also have a separate volume where I have set up a Perforce client (let's call it MyClient) and checked out all of the necessary sources from the depot.
  • As described on the page linked above, I have teamcity.agent.failBuildOnCleanCheckout=ignoreAndContinue as a parameter in my build configuration and I have enabled bootstrap steps.
  • I have bootstrap steps to attach my depot volume with aws ec2 attach-volume so that my checked out sources end up at D:\depot and then send a setParameter service message to set the vcsroot.<id>.p4client parameter to MyClient. I also have the configuration parameter teamcity.perforce.agent.reuse.client=true, so it will use MyClient instead of creating a new client.

When I tried to run this build, it ran the bootstrap steps, and then modified MyClient so its root was C:\BuildAgent\work\<hash> before trying to sync. I suppose this makes sense, because the Version Control Settings had Checkout directory set to Auto. So I changed the settings to use a Custom path of D:\depot and ran the build again. This time, the build failed before it even got to the bootstrap steps. The error it gave was "Agent failed to create build checkout directory at D:\depot. Please check agent has necessary permissions and there is enough free space on disk.

So it appears that it tries to create the checkout directory even before the bootstrap steps run, which fails because the bootstrap steps are responsible for mounting the drive that the checkout directory is on. As a workaround, I tried to set teamcity.build.checkoutDir in a setParameter service message during the bootstrap steps so that the checkout directory is set to the correct path after the drive is mounted, but it appears that this has no effect.

Can someone please provide guidance on what I'm doing wrong? Thanks.
 

0
4 comments
Dear Andya,

I think that having a separate build configuration (let's call it "mount") that will not checkout anything and will just mount the D:\depot should work. You should then create a snapshot dependency in the already existing build configuration for it to depend on "mount", disable "do not run new build if there is a suitable one", and enable the "run build on the same agent" options.
I will confirm the moment when the checkout directory is checked. Please let me know if the above works for you.

Best regards,
Anton
0
Dear Andya,

I've confirmed that, yes, the checkout directory is created/checked before the bootstrap steps (basically, bootstrap steps are already executed in the checkout directory). Then, the bootstrap steps, then checkout itself.
Another option, along with the snapshot dependency one, is to not use automatic checkout. Instead, have an auto checkout directory, checkout in the mounted directory manually in the command line build step, and then work in it.

Best regards,
Anton
0

Thanks, it sounds like either of those will work, but I ended up trying a third option that also does the trick. Just in case anyone has a similar problem and comes across this, I'll share it here. I set the Checkout directory in Version Control Settings back to Auto and let it create an empty checkout directory in C:\BuildAgent\work\<hash>, but then in my bootstrap steps, I remove that empty directory and replace it with a symlink that it points to D:\depot, so by the time the sync actually happens, the checkout directory is populated with previously checked out sources.

0
Dear Andya,

Thank you for sharing another option. I'm glad to hear that it is working for you now.

Best regards,
Anton
0

Please sign in to leave a comment.