Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSTS Online Portal: Un-Nesting Build Folders on Release

I'm trying to set up automatic build + deploy for a rather large solution. The single solution produces 2 zip folders in the "$(Build.ArtifactStagingDirectory)" location, and these contain all the right files. For the purposes of testing/troubleshooting I am only looking at one of these zip files, but eventually both sites will have to be deployed this way.

However, to get to the actual files, you have to pass through 14 unnecessary subfolders. To further complicate matters, about 8 of these are variable, based on certain elements of the build configuration (some are due to folder structure in the git repo).

I don't want any of these subfolders. The other problem is that I don't actually want a 100% flat file; I need 2 folders with subfolders to be contained within the finally-extracted directory. (The final directory is a physical path for an IIS site.) Is there any way to do this?

I have tried:

  • Taking the generated zip file, extracting it to a temp directory, and repackaging it, all on the build machine.

    • To get this to work, I had to manually specify the 14 subdirectories. Also, I was unable to use "Publish Artifact" to upload the resulting zip to VSTS, so I'm not sure how to get it onto the server box.
  • Downloading the published zip file from VSTS, extracting it locally on the release machine, and then copying the contents to the correct directory.

    • This works only when I manually specify the 14 folders contained in the directory. I made an attempt to hide the 14 folders with wildcards but only succeeded in copying the excessive nesting structure - I'm guessing the "Source Folder" parameter doesn't support wildcards (I had to actually do it in the "Contents" section or the task failed).
  • Using the "Flatten Folders" advanced option in the copy dialog.

    • This removes ALL folder structure, which is not what I want. I need to end up with 2 folders containing subfolders in the final directory.

If it's not possible to only partially flatten the zip generated by the build step, I'd appreciate some help figuring out how much of this terribly convoluted path I can pull out using variables.

like image 634
thecoloryes Avatar asked Aug 28 '17 17:08

thecoloryes


2 Answers

There is a very simple way to move the contents of only the contents and subdirectories the PackageTmp folder to the build artifacts folder while shedding the unnecessary folder structure above it, and without using the "Flatten Folders" option (since you likely want to keep the folder structure under PackageTmp intact):

First, in your Build Solution task, set the MS Build Arguments similar to the following:

/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=false /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.binariesdirectory)"

Notice that /p:PackageAsSingleFile=false is set to false; you don't want to zip the package up just yet. Also note the setting /p:PackageLocation="$(build.binariesdirectory). You don't want the output to go directly to the artifact staging directory, as is configured by default.

Next, add a Powershell task, and add this inline script:

$folder = Get-ChildItem -Directory -Path '.\*' -Include 'PackageTmp' -Recurse
Write-Host "##vso[task.setvariable variable=PathToPackageTmpFolder]$($folder.FullName)"

This will store the fully qualified path to the PackageTmp folder in a variable named PathToPackageTmpFolder. Under Advanced options, set the Working Directory to $(build.binariesdirectory)

Now add a Copy Files task to move only the contents of PackageTmp and its subfolders to the artifact staging directory. Set Source Folder to $(PathToPackageTmpFolder), Contents to **, and Target Folder to $(build.artifactstagingdirectory). You're all set!

like image 87
Byron Jones Avatar answered Oct 09 '22 18:10

Byron Jones


That is the MSBuild deploy/publish to package action and the folder structure won’t be remain after deploying to the server.

You can specify /p:PackageTempRootDir="" msbuild argument to ignore the folder structure of project path.

Another way is that, you can publish project through FileSystem method, then archive files through Archive files task.

like image 35
starian chen-MSFT Avatar answered Oct 09 '22 17:10

starian chen-MSFT