How To Reliably Delete Contents of Dir After "##teamcity[publishArtifacts ..." ?

Question:
       How can I make sure a directory is empty after I have done a "##teamcity[publishArtifacts"?  That is, what is the best way to delete a directory's contents after artifact publication.


Goal:
        Make sure each test in a single build does not leave data which will confuse tests which come afterwards.


Background:
        My users call "##teamcity[publishArtifacts" for each test in a build.  There can be several dozen "publish" calls during the life of a build. Here is an example (note: we use Ant as the builder language):

<echo message="##teamcity[publishArtifacts '${results.dir}']"/>

I want to delete the contents of ${results.dir} when the publish finishes.  I tried something like this:

    <echo message="##teamcity[publishArtifacts '${results.dir}']"/>

    <delete includeemptydirs="true">

        <fileset dir="${results.dir}" includes="**/*"/>

    </delete>


That didn't work.  The log indicated the deletion happed before the publish happened. Here is a log extract:

[16:45:12]: [echo] ##teamcity[publishArtifacts 'D:\work\Staf_Trunk_XPS_CLT\stafTests\Results']
[16:45:12]: Publishing artifacts (4s)
[16:45:12]: [Publishing artifacts] Paths to publish: [D:\work\Staf_Trunk_XPS_CLT\stafTests\Results]
[16:45:16]: [Publishing artifacts] Sending files
[16:45:16]: Artifact "D:\work\Staf_Trunk_XPS_CLT\stafTests\Results\0_Split_View_HTML_Diff\2_INCOMPLETE - APL Chassis Divorce Block Setting (CHDBLK) #4 at Sat 14 Jan 1636.html" does not exist and will not be published to the server
[16:45:16]: Artifact "D:\work\Staf_Trunk_XPS_CLT\stafTests\Results\2_INCOMPLETE - APL Chassis Divorce Block Setting (CHDBLK) #4 at Sat 14 Jan 1636.html" does not exist and will not be published to the server
[16:45:16]: Artifact "D:\work\Staf_Trunk_XPS_CLT\stafTests\Results\APL Chassis Divorce Block Setting (CHDBLK)_#4\ChassisDivorceBlockSetting.properties.txt" does not exist and will not be published to the server
[16:45:16]: Artifact "D:\work\Staf_Trunk_XPS_CLT\stafTests\Results\APL Chassis Divorce Block Setting (CHDBLK)_#4\Client1\Log.20120114_163640.txt" does not exist and will not be published to the server
[16:45:16]: Artifact "D:\work\Staf_Trunk_XPS_CLT\stafTests\Results\APL Chassis Divorce Block Setting (CHDBLK)_#4\Client1\Log.txt" does not exist and will not be published to the server
[16:45:16]: Artifact "D:\work\Staf_Trunk_XPS_CLT\stafTests\Results\APL Chassis Divorce Block Setting (CHDBLK)_#4\STAX_Job_4.html" does not exist and will not be published to the server
[16:45:16]: Artifact "D:\work\Staf_Trunk_XPS_CLT\stafTests\Results\APL Chassis Divorce Block Setting (CHDBLK)_#4\STAX_Job_4.txt" does not exist and will not be published to the server
[16:45:16]: Artifact "D:\work\Staf_Trunk_XPS_CLT\stafTests\Results\APL Chassis Divorce Block Setting (CHDBLK)_#4\STAX_Job_4_User.html" does not exist and will not be published to the server
[16:45:16]: Artifact "D:\work\Staf_Trunk_XPS_CLT\stafTests\Results\APL Chassis Divorce Block Setting (CHDBLK)_#4\STAX_Job_4_User.txt" does not exist and will not be published to the server
[16:45:16]: Artifact "D:\work\Staf_Trunk_XPS_CLT\stafTests\Results\APL Chassis Divorce Block Setting (CHDBLK)_#4\XPS\xpslog_20120114163620811.log.txt" does not exist and will not be published to the server
[16:45:16]: Artifact "D:\work\Staf_Trunk_XPS_CLT\stafTests\Results\APL Chassis Divorce Block Setting (CHDBLK)_#4\out.scr_ChassisDivorceBlockSetting.txt" does not exist and will not be published to the server
[16:45:16]: Artifact "D:\work\Staf_Trunk_XPS_CLT\stafTests\Results\APL Chassis Divorce Block Setting (CHDBLK)_#4\scr_ChassisDivorceBlockSetting.txt" does not exist and will not be published to the server
[16:45:16]: Artifact "D:\work\Staf_Trunk_XPS_CLT\stafTests\Results\KilledApps.txt" does not exist and will not be published to the server
[16:45:16]: Artifact "D:\work\Staf_Trunk_XPS_CLT\stafTests\Results\testtimes.txt" does not exist and will not be published to the server
[16:45:16]: [Publishing artifacts] Artifacts path Results not found
6 comments
Comment actions Permalink

Hello Tennis.

Artifacts publishing via Service Messages is done in background.
You can use Swabra to clean up newly created files so that subsequent build runs are not affected. Take a look at Swabra documentation.

If using Swabra is not an option, could you please give some detailed information on what kind of artifacts are pulished and how do they affect test runs inside single build run?

0
Comment actions Permalink

Thanks!  I'll look at Swabra.  

0
Comment actions Permalink

After looking at the Swabra docs, something else comes up:   Each test is using the same output directory.  Will Swabra make the next test pause while it cleans the output directory?
-T

0
Comment actions Permalink

Hi

The directory is cleaned afted a build is finished. Files are not deleted between tests.

Can the artifacts be created in another directory, so they are not mixed with temporary files?

0
Comment actions Permalink

Unfortunately not, Swabra does not pause the build, as it runs once after the build or before the build (right after checkout).

Could you give me some more details on artifacts you want to publish and clean. What do they contain? How do they affect subsequent tests?

0
Comment actions Permalink

Can the artifacts be created in another directory, so they are not mixed with temporary files?

That's what I'm thinking too.  Its probably cleaner to do it that way anyhow.

-T

0

Please sign in to leave a comment.