Search code examples
c#teamcityartifactsteamcity-rest-api

Teamcity REST API: get an artifact path


I have some problem: Have a build with n steps. Last step is a custom c# notifier, that sends emails about build state. Now I need to receive artifacts and attach them to my email. The problem is that at last step we don't have already zipped artifacts, that's why we need to find them ourselves and zip. In some configurations I don't have any property "checkout directory". So, how I can get root checkout folder and artifact path?


Solution

  • In order to attach files to your email I don't think you need to be using the REST API, but inbuilt parameters to find out various paths and locations. Without fully understanding your build pipeline I can only have a guess that this is what you need to know.

    In built parameters

    TeamCity offers a number of parameters that will help you with various paths

    • %teamcity.agent.work.dir% - This is the working directory of the agent
    • %teamcity.build.checkoutDir% - This is the checkout directory of the agent
    • %system.teamcity.build.tempDir% - This is the temporary build directory

    Outputting these as part of a simple build, mine are:

    enter image description here

    Looking in the build log will help you work out where various bits are going. Again without fully appreciating your build setup I can only generalise, but here we can see that a .nupkg is being produced in the checkout directory.

    enter image description here

    TeamCity won't publish artifacts until after the last build step has executed in a build configuration, unless you want to force this using ##teamcity[publishArtifacts '<path>'], but I don't think that will help you unless you are trying to then call the REST API to get to the artifacts.

    Hope this helps.