VSTS Drop Single Artifact - Release to Azure Multiple Websites - azure

I have a Visual Studio Solution which has multiple websites projects.
I'm currently running a build in VSTS against 1 repository which is creating a drop.zip artifact that has produced 3 websites segmented by their project/folder name.
Now I'd like to have 3 release definitions which publish each of the respective folders to Azure App Service.
How can this be done?
Inside of the Azure App Service Release step, I can only point to a single Zip file. I need to point to a folder inside the Zip the file, correct?

You could create a zip for each of you 3 websites. Publish the websites separately to 3 different build artifacts in the build pipeline.
In the release definition add all 3 artifacts in the artifacts section and deploy them to their respective Azure App service.

It does not must be a zip file. Just as the high-lighted section in your screenshot. It could be a package file or folder.
So for your scenario, you just need to configure the 3 release definition to link to the same build artifact. And then in the release definition add two tasks:
Extract files Task - Use this task to extract the zip file
Azure App Service Deploy Task - In this task, set "Package or folder" path to the extracted project folder.

I was able to get this working by using the following MSBuild configuration:
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=false /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactstagingdirectory)" /p:DeployIisAppPath="Default Web Site" /p:Configuration=Release /p:Platform="Any CPU"
This generated a separate Zip file for each Web App in the solution.

Related

Azure devops build pipeline- publish artifact process

I have created the azure build pipeline for my website application. In this, there is a task of Publish Artifact Which I think supposed to publish a website. But right now it is publishing without the dlls. Means it contains the *.aspx and *.aspx.cs files. It supposed to create the dll files for *.aspx.cs files. Could you please let me know which publish option/task I am supposed to choose for my website. Which will be equivalent to the "Publish Web App" command in the azure build pipeline.
right now it is publishing without the dlls. Means it contains the
*.aspx and *.aspx.cs files.
For this issue, I tested publishing the website to local in vs. From the local file directory, we can see that the dll files are in the Bin folder. You can set the system.debug=true variable when running the pipeline, so you can track which folder the dll files are published to in the build solution step in the log.
About publishing artifact process:
Artifacts are the files that you want your build to produce. Publish artifact task is used to publish artifacts for the Azure Pipeline.
In the agent there are 3 folders: a, b and s. The variable $(Build.ArtifactStagingDirectory) point to folder a (artifacts). When you build the code all the code and the artifacts exist on folder s (sources), the best practice is to copy only the artifacts to folder a and then use the task "Publish build artifacts", in this task you take the artifacts from folder a and put them on Azure DevOps storage or in your file share.
If you save the artifacts in Azure DevOps you can access your artifacts from the build summary page or create a release pipeline. if you save them in a file share you can just access them there or in the release pipeline.
In addition, you can share your build definition and msbuild arguments for further investigation.

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 deploy Azure WebJob as part of automatic VSTS deployment

Is there a way of having my Azure WebJob automatically deploy without needing to right click and select "Publish as Azure WebJob" every time? i.e. when I check-in my solution it is automatically deploy to the Azure Portal webjob section
While I tried to accomplish this, I found out that there is no tooling support for dotnet core projects as of now. The proposed webjobs.props/ msbuild solutions are all dotnet framework specific.
However I also found out that a webjob can be anything that's executable on the local machine (could be node.js or just a batch command).
The key is to understand how WebJobs are recognized by the host:
A WebJob on a Windows host is (by what I gathered from experimenting with it) just a run.cmd file that contains instructions on how to start the webJob. For dotnet core that would be dotnet MyDll.dll %* (%* to pass arguments for output redirection etc. down from the host).
Now depending on wether the job is continuous or triggered the run.cmd file needs to be located either at app_data/jobs/continuous/[NameOfJob] or app_data/jobs/triggered/[NameOfJob]. For the triggered job you could also add a schedule using a settings.job file like described here.
If there is a run.cmd at the proper location it will be recognized as a WebJob
Now to deploy a webjob using VSTS regardless of the runtime framework follow these steps:
Build/Publish your WebJob if necessary to get the executables
Add a run.cmd file next to your webjob executables that contains the proper startup instructions. You could also add settings.job here if needed.
Create the folder hierarchy app_data/jobs/[triggered/continuous]/[nameOfJob] and copy your executables into the lowest folder. Make sure run.cmd is directly under the [nameOfJob]/ directory
Zip the app_data folder so that the zip-package contains the entire hierarchy
Publish your zip file using the normal Azure App Service Deployment task (just like deploying the web app)
And that's it.
Yes you can.
Brady Gaster has written about this on a blog post (haven't tried it myself).
From what I gather, the TL;DR; summary is the following:
add a file named webjobs.props to the properties folder of the Web Application Project or Console Application you’re publishing
After that, edit the file so the ManagementCertificate, SubscriptionId and PublishSettingsPath are filled with correct data.
Now you should be able to publish the files using the command
msbuild WebJobDemo.Web.csproj /p:DeployOnBuild=true /p:PublishProfile=WebJobDemo /p:VisualStudioVersion=12.0 /p:Password=asdfasdf
(Note, post is written for VS2013)
Afterwards you should see something like this.
You could of course automate this in VSTS (or any other build/deployment tool for that matter) whenever something is checked in to your repository.
A (rather complete) answer on how to do this in VSTS via the command-line can be found in this answer: https://stackoverflow.com/a/45703975/352640
You can do it through Continuous Integration Build (trigger the build once check in).
Regarding deploy WebJob, you can generate a package through Visual Studio Build task with /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.stagingDirectory)" argument.
Then deploy it through Azure App Deployment task.
More information: Deploying and Schedule Azure WebJobs from VSTS to Azure Web App
In Visual Studio in order to enable automatic WebJobs deployment together with a Web project right-click the Web project in Solution Explorer, and then click: Add > Existing Project as Azure WebJob and create your WebJob.
More details can be found in an article by MS - webjobs-dotnet-deploy-vs

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.

Excluding a folder from release in vsts

I am using azure web apps with VSTS to build and deploy my web app.
All works great but I recently aded an extension to the web app, via Azure, which adds dll's to the site.
Now when I do a deployment, the deployment fails as the files are locked (by deployment, I should say 'Release').
One thing I am wondering, is it possible to exclude the folder from being copied over in the release? There's no need to copy the files anyway, and they're a seperate sub folder to the main dll's.
Thanks!
You can exclude the folder by specifying ExcludeFoldersFromDeployment property, then the folder will be excluded during deploy/publish to the package, then deploy the package to the azure app service through Azure App Service Deploy task directly.
For example: MSBuild argument of Visual Studio Build task:
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\" /p:ExcludeFoldersFromDeployment="[folder path that relative to project file]"

Resources