.net core azure pipeline deployment with editable folders - azure

I have a .net core web app (NopCommerce 4.1) that I am attempting to setup a build and release pipeline for.
However, when I setup the pipeline my deployment is failing because it attempts to create a folder, but write rights do not exist. I have confirmed this with Kudu where I get an error message (409) when attempting to create a folder via the cmd shell.
NopCommerce requires a couple of folders to be editable, but azure pipelines deploys a zip folder and creates a folder structure that is read only.
I want to deploy to a dev, test, prod environment with a folder structure that is editable (as nopcommerce creates folders and writes files to them dynamically).
I followed the following YAML structure:
https://damianbrady.com.au/2018/10/11/what-yaml-do-i-need-for-azure-pipelines/
Is there a way to create a build / deployment that will deploy either:
1. The files without zipping
2. Transfer a zip, unpack into a folder structure with execute/modify/create permissions

1.The files without zipping 2.Transfer a zip, unpack into a folder structure with execute/modify/create permissions
We could use the Azure kudu Zip API to do that.
Note:It is not recommended for deployments Kudu's zip API.
Kudu Rest API is an effective way to move multiple files to your site, but zipdeploy is preferable for deployment For more information please refer to this document.
In your case, you could use a Powershell task with Powershell script to invoke Kudu Zip API to do that. For information about how invoke REST API with Powershell, please refer to this SO thread.

Related

how to configure webjob to access the web app's reference project files in azure

I have a .net core web app that I deploy to azure using Azure Devops build/release pipelines. This project references Business project and a Models project that are part of the three-tier solution. The Models project consists of Entity Framework 6 code first models (including migrations).
Recently I have had to deploy a triggered webjob in order to accomplish a long running task. This was just created as a normal .Net console app and then published from within Visual Studio 2017 by selecting "Publish as Azure Web Job". This webjob is published to and runs under the .net core web app service mentioned above. It references the same Models and Business project that the .net core web app references.
My issue is that whenever the model is changed by introducing db migrations, the web job also must be updated since the models.dll that is published as part of the webjob project resides separately in a directory app_data\jobs\triggered\webjob under the main web app.
Is there any way to configure my webjob so that the models.dll and business.dll are directly referenced from that of the main web app? Failing that, how can I modify the Azure devops process to copy these files to the directory of the webjob upon successful deploy? Is there a guide for this?
how can I modify the Azure devops process to copy these files to the directory of the webjob upon successful deploy? Is there a guide for this?
AFAIK, we could use powershell scripts and git command to filter whether the file modification comes from models.dll and business.dll files, like:
$editedFiles = git diff HEAD HEAD~ --name-only
$editedFiles | ForEach-Object {
Switch -Wildcard ($_ ) {
'SubFolderA/models.dll*' { Write-Output "##vso[task.setvariable variable=UpdateFile]True" }
# The rest of your path filters
}
}
Code comes from here.
Then add custom conditions in the next task in the build pipeline:
and(succeeded(), eq(variables['UpdateFile'], 'True'))
In the next task, we could use the kudu API to update these files to the directory of the webjob upon successful deploy:
GET /api/zip/{path}/
Zip up and download the specified folder. The zip doesn't include the top folder itself. Make sure you include
the trailing slash!
PUT /api/zip/{path}/
Upload a zip file which gets expanded into the specified folder. Existing files are not deleted
unless they need to be overwritten by files in the zip. The path can be nested (e.g. `folder1/folder2`), and needs to exist.
You could check the similar thread and the document for some details.
Hope this helps.

Upload custom exe to Azure Devops pipeline

I'd like to execute a command line app that I created as part of my CI builds.
The command line app is not related to the repository on which the build is running. (Basically, its a tool that is supposed to send some project related metadata to a company web application to gather some metrics).
It seems I can execute it using a Command Line task, as explained here:
How to execute exe in VSTS Release pipeline empty process
The question is, however - how do I upload my custom tool into Azure Devops?
I know it's possible to create custom tasks (https://learn.microsoft.com/en-us/azure/devops/extend/develop/add-build-task?view=azure-devops) , but it seems quite a lot of effort to create, especially given that I have a console tool that is doing what I need.
I do this by including a seperate deployment folder in the git repo with my source code. This folder contains all the extra stuff (exe's) that I need to call to deploy.
You could if you wanted keep these artifacts in a different repo and/or different artifact if you wish as you can get any number of different artifacts
Then I include the deployment folder when publishing artifacts. In your build step you pull down the artifacts and it includes your EXE.
You're meant to be able to use things like NPM to install helper libraries on the fly but none of my required libraries were ever supported.
You can also use a self hosted agent which is your own host (Often an Azure VM). You install everything you need on there then you install a DevOps self hosted agent which lets build pipelines use it.
Create a build of your exe
Upload your exe to blob storage.
Create a SAS token to access your blob.
In your build create a task with a PowerShell script. In the PS script download your exe (unzip), and copy it to Build.StagingDirectory/"yourToolFolder". Then in your PS script run it. You probably want to pass it arguments like the location of the repo on the build agent.
A way to achieve this involve create a deployment group and add a server to the group where you have access and privileges to upload your console. it could be onprem or cloud depends in your requirements.

TFS to Server IIS Deployment -Include empty folders in App Data

ON deploying from TFS 2015 to onpremise Server,it deletes empty folders in App Data Folder.I want to include the empty folders in AppData and set Read,write/full control permissions to that folder.I use WINRM IIS Web Deployment task.
This is how the feature has been designed. Take a look from our MSFT'S reply at this similar question: Publish Artifacts task does not copy up empty folders
I can confirm this is by design. I am assuming you are uploading
artifacts to Azure DevOps Service rather than to your own file share.
You should think of Azure DevOps Service's artifact storage more like
blob storage than a giant file share.
I see you say you need these empty directories at deployment time. Can
you create them as a step during the release rather than as a step
during the build? I would say that fits best with the build vs.
release abstraction.
Compressing all of your artifacts into a .zip before you copy them to
the artifact staging directory should also work. You will just have to
unzip them as part of the release.
As suggested, you can create the empty folders via a script to workaround the issue. It will also apply to the situation if you choose to publish to file share path. Besides, you could also zip the artifact and upload and unzip it during release.

Adding additional files to VSTS Release to azure web app

I have a release in VSTS to deploy my webapp to the azure app service. For this I use a Azure App Service deploy step. After the normal deploy of the webapp I want to add an additional zip artifact from another build result. I want to copy only those file to a specific path of the web application on azure. How can I do that?
If the zip file is the web deploy package, you can refer to Joy’s answer. (Need to check Application option)
Otherwise, the simple way is using Kudu REST API (remain folder structure), steps:
Uncheck Publish using Web Deploy option of Azure App Service Deploy task
(Optional) Add Unzip task to extract zip files to a folder in artifact folder (the folder that you want in app service, e.g. D:/1/a/mylib)
Specify folder (parent folder of step 2 to remain folder structure) or package (zip) in Package or folder input box
You could use Virtual applications and directories to do it.You could check my steps.
Go to azure portal -> APPLICATION -> APPLICATION SETTINGS->Virtual applications and directories
set virtual directory with virtual path : /YourApplication to site\YourApplicationorsite\wwwroot\YourApplication
Go to VSTS-> the release option-> the Deploy Azure App Service task
set virtual application to /myApplication
Hope it can help you.
If using Azure DevOps for your CI then an alternative solution is to zip your file(s) including directory structure from the web root and add them into DevOps as a 'secure file' (find this under library/secure files once you've configured an Azure KeyVault).
Then add a pipeline task to download the secure file (use "Download secure file" task) to your build server. Make sure you add a "Reference name" to this task so you can reference the downloaded file path in a later step.
Then add a stand-alone "Azure App Service Deploy" step to deploy just this zip file. Select deployment method of "Zip deploy" and reference your downloaded secure file in the "Package or folder" section, like $(secureFileReferenceName.secureFilePath).
This effectively downloads the zip file from secure storage to the build agent and unzips it to wwwroot in the App Service.

How to publish and deploy a .Net Console application in similar way as Web application?

We have several Build definitions setup at TFS online (visualstudio.com) which delivers our Web application to several Azure machines (DEV, TEST, AccTest etc..).
It works and they trigger on build events.
BUT: Now we have added a Console Application (Batch exe file) that don't have a publishingProfile. The Build definition builds entire solution (console project is a part of that), but when it comes to Deployment only Web project is deployed in another folder and zipped.
I have read a lot on Stackoverflow and MSDN sites. But could not really find any spot on answers. This must be a common scenario that you have non-web projects in a solution that also needs to be deployed on same server through VSTS.
You can archive the files you want to deploy as a zip file, and specify the zip file as Package or folder option in Azure App Service Deploy task.
Detail tasks and settings to deploy the .net console app to azure as below:
1. Copy Files task
Source Folder: $(System.DefaultWorkingDirectory)
Contents: ProjectName\** or you can specify the certain file (such as *.exe) to copy
Target Folder: $(Build.ArtifactStagingDirectory)
2. Archive Files
Root folder (or file) to archive: $(Build.ArtifactStagingDirectory)
Archive type: zip
Archive file to create: $(Build.ArtifactStagingDirectory)/deploy.zip
3. Azure App Service Deploy
Specify Azure subscription and App Service name as you set before.
Package or folder: $(Build.ArtifactStagingDirectory)\deploy.zip
Now files you copied from .net console project are deployed to your Azure App service.

Resources