azure-devopsazure-pipelinesazure-devops-server-2019azure-devops-self-hosted-agent

How to change the agent build directory?


My Azure DevOps pipeline currently creates the path "C:\Agent-xyz_work\23\s..." for keeping the build output that will be used in the sub-project builds. Is there a way to set the build folder as just "C:" or "C:\w" etc? I need this because there is a custom build action by one of my third-party Wix toolsets that truncates the path when it gets too long. To keep it short, I want to keep the path as short as possible.


Solution

  • The agent installed directory as stated from the predefined variables is:

    Agent.HomeDirectory: c:\agent
    

    The agent working directory is

    Agent.WorkFolder : c:\agent_work
    

    Inside this folder (C:\agent\work\builID), you can locate some subfolders:

    • a -> artifacts
    • b -> build directory
    • s -> source directory

    You could use a powershell script and copy any artifacts or build outputs on the folder you want.

    Powershell example:

    $destinationFolder = "C:\myfolder"
    $sourcesDirectory = "$(Build.ArtifactStagingDirectory)\result"
    robocopy $sourcesDirectory $destinationFolder /im /e
    

    https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml