Azure DevOps Extract Files task doesn't preserve hierarchy - azure-devops

I am new to ADO, so am probably misunderstanding this, or just doing it wrong, so please be patient.
I want to deploy my web site to my server via FTP. As far as I can see, the build creates a zip file, which I need to extract, and then upload the extracted file. Please correct me if I got this wrong, because if I did, then what follows is probably irrelevant.
I have set up a release pipeline (started with an empty one) and added an Extract Files agent job...
I then added an FTP Upload task to upload the extracted files to my server...
The problem is that my server ends up with all of the files in the root folder. The hierarchy has been lost completely...
There should be a wwwroot folder there with the static content. The folder doesn't exist, and the static files (such as the *.js and *.css files you see in the screenshot) are all in the root folder.
The zip file did contain this folder...
Anyone able to explain what I did wrong?

Azure DevOps Extract Files task doesn't preserve hierarchy
When you want to keep folder structure with FTP Upload task, you can select the checkbox preserve file paths in the FTP Upload task settings.
If you didn't, please check it, then the files folder structure will be preserved:
Hope this helps.

Related

Azure DevOps AzureBlob File Copy Task Wildcard Directory Source Path

I have a Release Pipeline setup to extract my build artifact and then I use the RegEx Find & Replace task to update a few configuration files on my static website before uploading via AzureBlob File Copy task.
What I have currently works. However I have to use the full source path to the "wwwroot" folder in order to for the correct files to be uploaded.
My concern is that my builds may change the directory structure that gets dropped as a build artifact which will break my release tasks.
I've tried to use various wildcards for the source path such as:
**/wwwroot/*
*/*wwwroot/*
And many other variations to no avail.
I read in some of the docs that wildcards won't work for directory paths in this task but was hoping there was a way to work around this as I have long term concerns about the path changing over time. I looked at a few other tasks in the marketplace but nothing seems to fit the bill and I couldn't find any definitive guidance on the matter. Any suggestions?
1.You can use $(System.DefaultWorkingDirectory)/**/wwwroot/*.*(or .json,.xml...) in Source input.
(If the wwwroot folder doesn't have subfolders and all files within that folder can match format *.*)
2.Otherwise I suggest you archive the wwwroot folder first before uploading it:
Use $(System.DefaultWorkingDirectory) to get working directory and then use full path(not recommend using * here) to archive the specific wwwroot folder. Then upload the zipped folder which contains all content of your wwwroot folder.

How can I copy just new and changed files with an Azure Devops pipeline?

I have a large (lots of dependencies, thousands of files) nodejs app that I am deploying with an Azure Devops YAML build and Azure Devops "classic editor" release pipeline.
Is there some way to copy JUST new and changed files during a file copy, not every single file? My goal is to reduce the time it takes to complete the copy files step of the deploy, as I deploy frequently, but usually with just changes to one or a few files.
About copying only the changed files into artifacts for releasing, if the changed files are in a specific folder , you can copy files in the specified folder by specifying SourceFolder and Contents arguments in the Copy Files task.
If the changed files are distributed in different folders, I am afraid that there is no out-of-the-box method to only pick the changed files when using copy file or PublishArtifacts task.
As workaround, we could add powershell task to deletes all files (recursive) which have timestamp that is < (Now - x min), with this way Artifact directory contains of ONLY CHANGED files. More detailed info please refer this similar case.
Alternatively, you can call Commits-Get Changes rest api through a script in the powershell task, and then retrieve the changed files in the response and then copy them to specific target folder.
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits/{commitId}/changes?api-version=5.0

How to get Web.config file in the root of a create-react-app project to copy to the build folder so it gets archived and deployed

I have a file copy task in my build to copy the Web.config in the root of my create-react-app project folder, and it shows that it is copying it to the build file after the yarn build task completes.
But it is never in the archived folder. How do I modify this build or copy files task to get this Web.config file into my build folder so that it can get archived and dropped for release?
I copy it from the $/repo dir/app folder to build (yarn build step creates the build folder)....but the Create release package that archives the build folder does not contain it in the produced zip.
Here's a screenshot of my folder structure in my repo (what's in the $/repo dir/app folder):
In the Copy task you need to specify full path of the build folder, for example:
$(Build.SourcesDirectory)/build
Because you have coded all the paths, I can’t analyze this issue according to your specific situation.
You can specify the Web.config file from ... to see if it can be successfully copied to the build folder.
It would be much easier for people to investigate further and reply if you could attach detailed file path and logs.
Include the web.config file in the public folder
Now the file gets included in the build and dropped for release

Deploying web app from Visual Studio Code to Azure but leave out a data folder

I am building a very small Node/Express API app in Azure using Twilio to route communication for a small group. I initially built out a data structure for users in CosmosDB but found out it's minimum $24 per month, which is way over budget for something that will likely hold 20 or so records. Because of this, is seems much more reasonable to just build this into a json file that sits in a ./json subfolder. However, it has occurred to me that whenever I deploy, I would be overwriting this file with the default file I have locally. I have been working via the Azure App Service tool in Visual Studio Code and can't figure out a way to make it ignore the file.
I can go into Kudu and copy the file down each time before I deploy, but I will eventually forget and this sounds like a very brittle process.
I added a json/ line to .gitignore, but that has no effect on the deployment (as expected).
I also added "appService.zipIgnorePattern": ["json{,/**}"] to the settings.json file, but instead of just ignoring that folder on the server, it erases it on deploy (the zip ignores it and then it wipes/replaces the whole wwwsite folder). Looking for the file gives me {"Message":"'D:\\home\\site\\wwwroot\\json\\users.json' not found."}
I was hoping there is a setting that would deploy, replacing all folders in the package, and ignoring all content in the ./json folder. Does this exist?
Alternative solution, 2021:
Instead of excluding folders, select the folder that you do want to deploy. Data in other folders will not be affected.
Deploy from: edit .vscode/settings.json in your local project and add "appService.deploySubpath": "./folderToDeploy"
Deploy to: In the Azure Portal go to your app service. Under Configuration / Application Settings add a new Application Setting with name SCM_TARGET_PATH and value ./folderToDeployTo
Using VS Code right+click deploy will deploy the contents of the folder. I was able to work around this by adding Azure as a remote branch and using .gitignore. I placed my json file inside a random folder (content/json) then placed /content/json in my .gitignore file.

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.
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!
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.