dotnet core 2.0 webjob deployment - VSTS - azure-devops

I want to deploy my webjob ( dotnet core 2.0 commandline application ) through 'release' defination. My drop folder contains webjob named 'MyWebjob.zip'. I want to copy this to my webapps below directory where all tasks exists
D:\home\site\wwwroot\App_Data\jobs\continuous>
Below is snap of of my existing release defination
Can anyone tell which copy job is suitable to copy contents from drop folder to 'wwwroot\App_Data\jobs\continuous' direcotry?
Or is there any easy way to deploy webjob ( dotnet core 2.0 ) using VSTS?
Note: I can't use FTP for some reason as 'Continuous Integration' is enabled for our project.

You can’t use these tasks to deploy webjob.
If you remain the folder structure (App_Data\jobs\continuous) in MyWebjob.zip file, you can deploy it to azure web app through Azure App Service Deploy task (App type: Web App; App Service name:[your app service]; Package or folder:[that zip file]; Check Publish using Web Deploy option).
Otherwise, I recommend that you can do it through Extract files and Copy files to organize the folder structure, then deploy through Azure App Service Deploy task (Package or folder:[App_Data parent folder]; Uncheck Publish using Web Deploy option).
You also can upload files through Kudu API (Extract zip file through Extract files task first)
There are some threads that can help you to call Kudu API in VSTS.
Remove files and foldes on Azure before a new deploy from VSTS
How to access Kudu in Azure using power shell script

You can add a custom target to your worker .csproj file.
<Target Name="UpdateWebJobsPublishDir" BeforeTargets="ComputeFilesToPublish">
<PropertyGroup>
<PublishDir>$(PublishDir)App_Data/jobs/continuous/$(ProjectName)/</PublishDir>
</PropertyGroup>
</Target>
The above vill update the output dir before it is publised. In VSTS/Azure DevOps you just deploy you project as normal webapp it will be put in the right folder.

Related

How to generate deployment files Azure DevOps - TFVC

I have hosted ASP.NET Core and .NET Windows application to DevOps Services - TFVC (Cloud)
Now, I am stuck with how to generate deployment files, like debug folder of .NET Windows app or cloud hosting files of ASP.NET Core.
I have created a pipeline to generate deployment files, but how can I execute from the local machine so that developer can get the necessary files to host or install?
Thanks.
Since you have created a pipeline to generate deployment files, you could add a archive task and a Publish build artifacts task to publish the target files.
Archive files: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/archive-files?view=azure-devops
Publish build artifacts: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/publish-build-artifacts?view=azure-devops
So the developers could download the .zip files from the pipeline summary page to host and use.

Copy or Rename file in sub folder under Web App through azure release pipeline after web deploy

I have an Azure DevOps release pipeline, deploying my code using Web Deploy to Azure Web app to different environments (Dev/ SIT/ UAT/ PROD). Now, I need to include a task to copy/ rename one Configuration file (environment specific), which is inside 'Config' folder, to another file inside the same folder. Please note, the config file is not under the root folder of the web app.
Is there a way to accomplish this using 'post deployment action' or command line script task? I couldn't understand how can I refer the source folder of the web app for the copy operation. I was referring the following page but couldn't find one that will help me to achieve the task. Any help is appreciated.
https://learn.microsoft.com/en-us/azure/devops/pipelines/release/variables?view=azure-devops&tabs=batch
The Post deploy action script is running on azure (through Kudu API): Command
So, if the file is existing on the azure web app, you could copy it through Post deploy action script, for example, Site.css is in wwwroot\Content folder after deploying, then the script could be like this:
Copy Content\site.css Content\site1.css /a
Otherwise, you could store the necessary data in App settings or Configurations of Azure Web app.

How do I deploy azure funtion app packaged as .nugpk using azure devops?

I have a build pipeline that generates .nupkg for azure function, when I try to release it the content gets deployed (I can see when I download the app content) but I cannot see the function.
Is it the case that azure artifact has to be .zip for azure function? I am able to deploy the angular and .net core app using .nupkg without any problem!
Is it the case that azure artifact has to be .zip for azure function?
You re right.
Currently, only .zip package files are supported.
That because:
Zip deployment is a feature of Azure App Service that lets you deploy
your function app project to the wwwroot directory. The project is
packaged as a .zip deployment file. The same APIs can be used to
deploy your package to the d:\home\data\SitePackages folder. With
the WEBSITE_RUN_FROM_PACKAGE app setting value of 1, the zip
deployment APIs copy your package to the d:\home\data\SitePackages
folder instead of extracting the files to d:\home\site\wwwroot.
You could check the document Run your Azure Functions from a package file for some details.
And there is state about that:
Hope this helps.

Deploy Azure App Service and Webjobs using Azure Devops in .Net Framework

I have created Azure AppService and added Webjobs console application in a single solution. I'm trying to build the solution through Azure DevOps build pipeline and Deploy the package through Octopus. When I build the solution there files required for Appservice such as Web.config and Global.asax are missing from Artifacts folder. so When deploying that package is breaking the AppService.
I tried to change the MSBuild arguments while building the solution. the current MSBuild arguments are as follows:
/p:DeployOnBuild=true/p:WebPublishMethod=Package
/p:Configuration=$(BuildConfiguration) /p:OutputPath=.\bin\ /p:PackageTempRootDir="$(build.artifactstagingdirectory)\temp" /p:packageAsSingleFile=true /p:TargetProfile=Cloud
I suspect, while building the Webjobs it is removing the App Service files, so the generated package does not contain all the required files. My Build pipeline looks like below.
My Artifacts folder Creates a Nupkg file which has following files.
If the App Service is deployed alone, It is working fine,Please suggest me the way I can deploy both from single solution and one Build definition on Azure devOps.

.NET Core Webjob does not publish when deployed through CD in VSTS

I have a dot net core 2.0 console app which I need to publish in Azure as webjob through continuous build and deployment in VSTS. I have created a web app already in Azure and defined CI and CD tasks in VSTS for the console app's project.
The issue is that whenever these tasks run, webapp gets deployed successfully but the webjob does not get deployed. However, it gets deployed when I use the artifact (zip folder created after build process) and upload it manually to Azure webjob section.
I think deploying the artifact using powershell script might be a solution but I have tried zipdeploy API of Kudu as well but to no use. Can someone please help or point me to a reference for extracting the artifact generated from build process and deploy it using CD tasks so that the webjob gets published alongwith webapp.
With general web application, if you link web job project to the web (right click web app in Visual Studio > Add > New Azure WebJob project/Existing project as WebJob), you can refer to these steps below:
Create a new build definition
Add NuGet Tool Installer task
Add NuGet restore task (Path to solution, packages.config: ***.sln)
Add Visual Studio Build task (MSBuild Arguments: /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\")
Add Publish Artifact task (Path to publish: $(build.artifactstagingdirectory))
Queue build
Create a new release definition
Add Deploy Azure App Service task (Package or folder: {web app zip file path}; Choose Publish using Web deploy)
Otherwise:
Create a new build definition
Add NuGet Tool Installer task
Add NuGet restore task (Path to solution, packages.config: ***.sln)
Add Visual Studio Build task (/p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:publishUrl="$(build.artifactstagingdirectory)\" /p:DeployDefaultTarget=WebPublish
Add necessary task to build web job project (e.g. Visual Studio build)
Add Copy Files task to copy web job’ build result to appropriate folder in web app published folder ($(build.artifactstagingdirectory)) (App_Data/jobs/continuous for continuous webjobs or App_Data/jobs/triggered for scheduled and on-demand WebJobs)
Add Archive Files task (Root folder or file to archive: $(build.artifactstagingdirectory); Archive file to create: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip)
Add Publish Artifact task
Create a new release definition
Add Deploy Azure App Service task (Package or folder: {web app zip file path}; Choose Publish using Web deploy)