Generic Pre/Post-Build Hook
Hi,
Since our developers are adopting docker for more and more builds, we are struggling with files from root or an unknown user inside the checkout directory on the agent, created during runtime of the container. These builds are mapping the checkout directory to a directory inside the container and are creating files, which then will stay in the checkout directory, and can't be cleaned from TeamCity because the file permissions won't allow it. Of course, we are urging the developers to fix their builds, but there will still be plenty of cases, where an agent ends up being blocked.
We are aware of the possibility to config a build step to run within a container in TeamCity. This does indeed solve the problem, as it changes the owner of the files after the build. But this solution moves quite a bit of the build configuration from the scripts in the Git repository to TeamCity, which we don't really want. Mostly because we want to use these scripts also to build locally.
What we have so far is a simple shell script to fix this file permissions before or after a build. We are trying to implement a template to be applied to problematic builds, which adds a step to run this shell script. But the easier solution for us would be to call this script before and/or after every build on an agent.
So, what we are searching is something like a hook in the agent software, so we can make sure, our script is called before and/or after every build. Is there a possibility to do something like that?
Thanks for your help!
By the way, we were also searching a solution based on docker, because the issue is known there as well. But the corresponding feature request is not implemented yet.
Please sign in to leave a comment.
Hi Iwan,
your scenario is indeed pretty interesting. I'm going to pass it along to the docker devs to see whether we can actually help with something else, but in the meantime I'm afraid that the only option is the first-and-last build step approach. While templates help with that, the other option would be to script your build configurations via the REST API or the files on the folder, or even easier, export your build configs to the Kotlin DSL, and then you could simply wrap the build configurations in steps that would do that. A similar approach is described in our blog when we introduced the Kotlin DSL: https://blog.jetbrains.com/teamcity/2017/01/kotlin-configuration-scripts-creating-configuration-scripts-dynamically/
Hi Iwan,
a quick follow up. After passing this internally, another idea might be to set up a plugin that hooks onto buildStarted event and runs your desired commands:
The OpenAPI should provide endpoints for that, https://confluence.jetbrains.com/display/TCD18/Agent-side+Object+Model can give some insight into it.