Search code examples
azure-devopsazure-pipelinesazure-pipelines-yaml

What directory should I use to manipulate files that will be consumed in other tasks, but not published as artifacts?


I need to manipulate some text files that are not going to be published as artifacts. They will be consumed by other tasks later on in the pipeline stage.

Best practice in mind, what directory should I be using? Build.ArtifactStagingDirectory, Pipeline.Workspace, Agent.TempDirectory or is there another?

I've been using Pipeline.Workspace, but not sure if this is best practice.


Solution

  • Rather than best practice I think the selection of a location would depend on the objective at hand and from the scenario you have outlined-

    I need to manipulate some text files that are not going to be published as artifacts. They will be consumed by other tasks later on in the pipeline stage

    Pipeline.Workspace would be appropriate and most suitable out of the three.

    Pipeline.Workspace gives you the ability to store and access something through the course of a pipeline stage and will get cleaned up automatically once the stage finishes so you don't need to worry about it.

    This is unlike Agent.TempDirectory which gets cleaned up after every pipeline job which means accessing something between jobs of the same pipeline stage won't be possible.

    When it comes to Build.ArtifactStagingDirectory, it won't be a suitable choice for your case because it is the space where something is placed with the intent of publishing it as artifact which clearly doesn't seem to be your objective and if there happen to be any artifacts chosen to be published in the stage, it will be difficult to maintain the separation.

    Besides these,

    Agent.ToolsDirectory, Agent.HomeDirectory and Agent.WorkingDirectory are for more specific purposes i.e. for use by tasks for switching version of tools, for containing the agent software and for the the working of the agent respectively.

    Build.SourcesDirectory and Build.BinariesDirectory are local paths used by the agent to download the source code files and to use as output for compiled binaries respectively.

    So for manipulating text files these other locations will not work.