Search code examples
azure-devopsazure-pipelines-release-pipelineazure-artifacts

How to modify Publish Artifact folder $(build.artifactstagingdirectory) prior its zip creation in VSTS Build process?


I defined VSTS build process till Publish Artifact steps. By default, VSTS agent creates 5 files in Publish Artifact location (c:\vsts-agent_work\1\a) including important build file i.e zip folder. When I checked zip folder, I found long path where my build files are located. folder path in zip -

\Content\C_C\vsts-agent\_work\1\s\ABCProject\obj\Release\Package\PackageTmp

I got to know that source of zip file is source directory after looking in _work folder-

C:\vsts-agent\_work\1\s\ABCProject\obj\Release\Package\PackageTmp

I wanted one folder (RDLCReports Folder) in C:\vsts-agent\_work\1\s\CCM2015MVC\obj\Release\Package\PackageTmp directory. I managed to create that folder using copy files task. I did this step before Publish Artifact step.

Problem is when Publish Artifact step is completed, I didn't get that folder in zip file.

below is snapshot of VSTS build process-

enter image description here

below is Publish Artifact location -

enter image description here

Please let me know how can add that folder in zip? and I also want to know which source path VSTS build has considered to make it as zip folder?


Solution

  • The contents in folder (c:\vsts-agent_work\1\a) is created at the Visual Studio Build task step. So that even if you managed to create RDLCReports folder in C:\vsts-agent\_work\1\s\CCM2015MVC\obj\Release\Package\PackageTmp using copy file task. It will not be copied and zipped to c:\vsts-agent_work\1\a again.

    There is a workaround to achieve this. If you want to keep the folder structure in the zip file, You can follow below steps:

    1,You need to add a Extract file task to extract the zip file in folder $(build.artifactstagingdirectory) to a different folder (eg.$(Agent.BuildDirectory)/Temp) enter image description here

    2, Add the copy file task to create RDLCReports folder inside the extracted folder in $(Agent.BuildDirectory)/Temp enter image description here

    3, Add a Archive files task to archive the files in the folder $(Agent.BuildDirectory)/Temp where folder RDLCReports is created.

    enter image description here

    Make sure uncheck option Prepend root folder name to archive paths and check Replace existing archive

    (For above example. My test project is named AboutSite and the zip file is AboutSite.zip. And the folder structure is Content\C_C\agent\_work\1\s\AboutSite\AboutSite\obj\Release\netcoreapp2.0\PubTmp\Out. You need to make a little change to the paths and file name according to your project.)

    For your project you may find the contents in C:\vsts-agent\_work\1\s\ABCProject\obj\Release\Package\PackageTmp is the same with your zip file. So there is an another workaround is to add copy file task and target this path C:\vsts-agent\_work\1\s\ABCProject\obj\Release\Package\PackageTmp . And then add the archive file task to archive this folder. However this workaround cannot keep the origin file structure.