Search code examples
restapiteamcityartifacts

teamcity rest api to get the number of builds generating artifacts


I want to know how to find the teamcity builds which have artifacts defined in the artifact paths section on general settings page

i tried this Teamcity REST API: get an artifact path but it doesnt answer my question

i want to get the count of teamcity builds which are generating some find of artifact (basically for which artifacts are defined in the artifact paths section on the general settings page) on a monthly basis. For eg- how many such builds triggered in the month of May.


Solution

  • you can get a list of builds, for example /app/rest/builds/?locator=buildType:<conf id>, extract the id and get the artifacts of this build

    /app/rest/builds/id:<buildID>/artifacts/children/

    <files count="1">
    <file name="result.zip" size="73785398" modificationTime="20190617T162953+0000" href="/app/rest/builds/id:45771/artifacts/metadata/result.zip">
    <content href="/app/rest/builds/id:45771/artifacts/content/result.zip"/>
    </file>
    </files>
    

    as you can see, I collect all files to result.zip, let's extract this ZIP and see what is inside

    /app/rest/builds/id:<buildID>/artifacts/children/result.zip/

    <files count="2">
    <file name="bin" modificationTime="19700101T000000+0000" href="/app/rest/builds/id:45771/artifacts/metadata/result.zip%21/bin">
    <children href="/app/rest/builds/id:45771/artifacts/children/result.zip%21/bin"/>
    </file>
    <file name="yaml" modificationTime="19700101T000000+0000" href="/app/rest/builds/id:45771/artifacts/metadata/result.zip%21/yaml">
    <children href="/app/rest/builds/id:45771/artifacts/children/result.zip%21/yaml"/>
    </file>
    </files>
    

    So, you can collect the specific builds, by last month, by status.
    You can collect the artifacts pats for each build.
    And you able to aggregate all results as you want.