Search code examples
restcontinuous-integrationteamcity

create a build artifact into TeamCity using the REST API


How can I add a new build artifact (a large log file in my case) to a (currently running) build using TeamCity's REST API?

My usecase:

After TeamCity sucessfuly builds my code, it is sent to an external server for unittests. As these can take a long time, I "detach" the build from the agent at that point (##teamcity[buildDetachedFromAgent]). After the unittest-server is done, it contacts TeamCity using its the REST API, finishing the build (and reporting any failed unittests). Now I would also like to "upload" some files (namely some potentially large log files) from the unittest-server to TeamCity as build artifacts. It seems there should be a REST API call to do this, but I couldnt find it in the docs. Any idea?


Solution

  • TL;DR

    Your use case seems to be very uncommon according to your description. TeamCity is not a storage tool, so there is no API to upload them. But you still can do something about that.

    A bit of explanation

    Unit tests are meant to be executed on the build agent during the build . That's part of CI process. If you need to perform some tests on a dedicated environment, they are typically considered (depending on the scope, project, and ultimately team) as integration/E2E/system ones. So first the application gets deployed to that server, and then the tests are being run against it. All these steps are parts of CI cycle, so the tests are still executed and controlled by your build configuration, running on build agents, and producing build artifacts.

    Solution

    With that being said, I assume you could have a good reason to keep doing this.

    So, instead of attempting to upload the artifacts, you can make use of dependent build and build chain concepts:

    1. Add another build configuration to the chain;
    2. Configure it to be triggered upon the finish of your initial build;
    3. Make it download the artifacts from the place where they are stored (e.g. your server or a dedicated artifact storage) to perform the rest of analysis and reporting for you.