Deploying a WebAPI project with several webjobs in Azure Devops - azure

I am trying to use Azure Devops to do CI/CD. I have created the appropriate Git triggers to build when I push and I create a new release whenever I have produced a new build.
In the release tab I am trying to deploy a WebAPI project with several webjobs using the "Deploy Azure App Service" template. All the logs seem to indicate everything goes fine, but in the end I have nothing when I check the app service in Azure!
I have tried many different configurations and even a few more templates. They all seem fine according to the logs, but nothing is actually ever deployed!
If I try to build/deploy from VS2017 it works beautifully!
QUESTION
what do I need to do in order to successfully deploy my code via Azure Devops
.
My build YAML file is fairly close to the default, only added the CopyFiles#2 due to another SO post suggesting it:
trigger:
tags:
include:
- slot*
branches:
include:
- dev
pool:
vmImage: 'VS2017-Win2016'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
name: $(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r)
steps:
- task: NuGetToolInstaller#0
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: CopyFiles#2
inputs:
targetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts#1
condition: succeeded() #and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
Second step I create a release from the artifacts produced via the YAML file.

Please add the following line in your package or folder option
$(System.DefaultWorkingDirectory)\*.*
It will make sure to pick all the files while deploying.
Also please refer to these ways to deploy webjob to azure:
Modify Visual Studio Build task to deploy webjob with FileSystem (MSBuild Arguments: /p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:publishUrl="$(build.artifactstagingdirectory)\\WebJob" /p:DeployDefaultTarget=WebPublish)
Add Delete Files task to release definition to delete bin folder (Source Folder:
$(System.DefaultWorkingDirectory)/WebJobVnext/drop/WebJob); Contents:bin)
Modify Azure App Service Deploy task (
Uncheck Publish using Web Deploy option.
Package or folder: $(System.DefaultWorkingDirectory)/[artifact name]
/drop/WebJob)
Hope it helps.

There are two main problems with your deploy task.
As Mohit said, you need to specify the zip file of the web project you want to deploy, not just the directory it is in.
You need to uncheck "Exclude files from the App_Data folder". This will prevent webjobs from deploying with the website
2.1 If you haven't, in Visual Studio, you need to right click your web project Add > Existing Project as Azure Webjob. Do this for every webjob project so it will package the webjobs with the website

Related

Error ASPCONFIG: Could not load file or assembly 'CrystalDecisions.CrystalReports.Engine, Version=13.0.2000.0 Azure DevOps CI Pipline

I am new to Azure DevOps, I am trying to move the development environment to Azure develops and build the CI pipeline as follows:
# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
This the default pipeline script suggested by the Azure platform.
This is the error sent to the email :
4 error(s), 8 warning(s)
EServices\web.config(68,0): Error ASPCONFIG: Could not load file or assembly 'CrystalDecisions.CrystalReports.Engine, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. The system cannot find the file specified.
Process 'msbuild.exe' exited with code '1'.
ASPNETCOMPILER(0,0): Error 1003: The directory 'D:\a\1\s\ulsa_1\' doesn't exist.
Process 'msbuild.exe' exited with code '1'.
Azure DevOps pipeline build error
I am using visual studio 2017 community edition
Telerik 2019 Q3
Crystal Reports 13.0.2000
The reason for this question is that the Crystal Report is not installed in the Microsoft-hosted agent. You can refer to this document for information about softwares installed in the Microsoft-hosted agent.
To solve this question, you can:
Use self-hosted agent. This method is relatively simple, you can use a machine with Crystal Report installed as an agent to run your pipelines. Click this document for detailed information about how to set a self-hosted agent.
Add Crystal Report related dlls to your repository manually. In this method, you need to create a new folder in your repository and add CrystalDecisions.CrystalReports.Engine dll in it. Then, you need to edit the Reference to change the path to the relative path in the repository of the dll.

Azure CI/CD: On-Premise deployment failing

I am trying to deploy my code from Azure to my local machine. The steps I followed:
Created deployment group
Run register script on my machine(the folders successfully created in C:\azagent)
Created pipeline.
For pipeline the generated YAML is:
# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetCommand#2
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
feedsToUse: 'select'
vstsFeed: 'a31f9237-4431-41f2-b1a9-4370c7dc4828/a3a86133-79b3-437a-bc19-9665a420de4e'
- task: VSBuild#1
inputs:
solution: '**\*.sln'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
restoreNugetPackages: true
- task: CopyFiles#2
inputs:
SourceFolder: '$(build.sourcesdirectory)'
Contents: '**\bin\$(BuildConfiguration)\**'
TargetFolder: '$(build.artifactstagingdirectory)'
CleanTargetFolder: true
OverWrite: true
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
When I run the pipeline, it doesn't give any error but in release part I get an error:
The solution I am using has multiple projects. I need to deploy three projects on my machine. This is the first time I am using Azure DevOps and I don't have any clue about the error. Online articles are mostly explaining about cloud deployment and I could not find much about on-premise. In short my requirement is to deploy three projects from my repo on my local machine whenever I push any changes to master branch. Is there any step by step guide to achieve the same? What is the step I missed in the setup? Any help is much appreciated.
According to the description of the error message, first you need to check whether the corresponding build pipeline is selected as the release artifact source.
Then you can check whether the download artifacts path is consistent with the file path to the package(Package or Folder) of the IIS web app deploy task.
System.DefaultWorkingDirectory : The directory to which artifacts are downloaded during deployment of a release. The directory is cleared before every deployment if it requires artifacts to be downloaded to the agent. Same as Agent.ReleaseDirectory and System.ArtifactsDirectory.
Example: C:\agent\_work\r1\a
For details, please refer to predefined variables document.
my requirement is to deploy three projects from my repo on my local
machine whenever I push any changes to master branch.Is there any step by step guide to achieve the same?
To achieve this , in yaml build pipeline ,you need to set CI trigger: Continuous integration (CI) triggers cause a pipeline to run whenever you push an update to the specified branches.
In release pipeline , you need to set build pipeline as release artifact source, and then enable Continuous deployment trigger: This instructs Azure Pipelines to create new releases automatically when it detects new artifacts are available.

Azure - How to build a WebJob using a Pipeline coded in a Yaml file

I am totally new to Azure, Pipelines, etc.
I am trying to create an App Service consisting of a web site and a WebJob (a background job that runs periodically). I want to build and deploy it using a Pipeline coded with a Yaml file.
I created a Visual Studio solution with a very simple ASP.Net Core web site (project "pipelines-dotnet-core"), and a simple .Net Core console program (project "WebJobsSDKSample").
I created the Yaml file to build, publish and deploy the web site to my App Service. This works fine and I can open the site in a browser.
I then extended the Yaml file to copy the output folder of the console program project to the publish folder of the web site, compress the result to a zip file and deploy that zip file. I understand that I have to copy the console program project output folder to /App_Data/jobs/triggered/app under the publish folder of the web site.
This new pipeline runs fine, and the web site still gets deployed correctly. However, when I open the WebJobs page of my App Service, it says "You haven't added any WebJobs".
The contents of my Yaml file is below. What do I need to change to correctly deploy the WebJob?
Also, if you could point me at clear examples of how to code a WebJob in a Yaml Pipeline file, that would be really helpful.
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
variables:
buildConfiguration: 'Release'
steps:
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
- task: DotNetCoreCLI#2
inputs:
command: publish
publishWebProjects: True
arguments: '--configuration $(BuildConfiguration)'
zipAfterPublish: false
- task: CopyFiles#2
displayName: 'Copy Console App to WebJob Location'
inputs:
SourceFolder: WebJobsSDKSample/bin/Release/netcoreapp3.1
TargetFolder: pipelines-dotnet-core/bin/Release/netcoreapp2.2/publish/App_Data/jobs/triggered/app
- task: ArchiveFiles#2
displayName: 'Archive WebApp'
inputs:
rootFolderOrFile: pipelines-dotnet-core/bin/Release/netcoreapp2.2/publish
includeRootFolder: false
archiveFile: pipelines-dotnet-core/bin/Release/netcoreapp2.2/pipelines-dotnet-core.zip
- task: AzureWebApp#1
inputs:
azureSubscription: 'test connection 1'
appName: 'WebApplication120200310093243'
package: pipelines-dotnet-core/bin/Release/**/*.zip

WebJob cannot be added from portal if deployment form source control is configured

Today we experienced the following message in Azure Portal
WebJob cannot be added from portal if deployment form source control is configured.
We assume that this is a new feature hence the spelling is incorrect: 'deployment form source control' should be 'deployment from source control'.
I have no clue where to set a setting that solved this.
It has to be somewhere in DevOps we assume.
We solved it by not disconnecting a pipeline.
We solved it by implementing a seperate WebJob Build/Release Pipeline.
Here are the steps that worked for us:
In Azure Portal
Create a virtual application in your app service
In DevOps
In your build pipeline
Important Notice: add the following Argument: --output $(build.artifactstagingdirectory) to the build step.
In your release pipeline
This deploys the WebJob to the correct directory. In our case: $(System.DefaultWorkingDirectory)/_ms-reporting-webjob-dev-CI/drop
Having a look at the Kudo Console in our App Service the file location for our WebJob is:
Kudu Console
The workaround that worked for me was uploading the webjob directly via the Kudu Console.
Open the Kudu Console by selecting "Advanced Tool" --> "Go" in Your App Service on the Azure Portal.
Once on the Kudu portal open a "Debug Console" --> "CMD"
Go to the directory for your webjobs: "d:\home\site\wwwroot\app_data\jobs\continuous\{job name}" (https://github.com/projectkudu/kudu/wiki/WebJobs)
Then drag and drop the .zip file you prepared to upload your webjob (https://github.com/projectkudu/kudu/wiki/Kudu-console)
The job will now be listed on the Azure Portal and be started.
I used the following physical path in the Virtual Application and it solved it for us
site\wwwroot\App_Data\jobs\triggered\jobname
We had the same issue and noticed there was an old deployment pipeline connected to our web job in the Deployment Center blade. Disconnecting this solved the problem for us and we were able to manually deploy.
I used Kudu console to upload the webjobs
You can go to the path D:\home\site\wwwroot\App_Data\jobs\ and then upload the webjob folder here and then this shows up in your Webjobs portal as well
Don't go for the new CICD pipeline creation of this issue. Don't use chrome/safer while disconnecting the deployment center. Please use the latest IE or Microsoft Edge. it will allow the disconnect of the deployment center. I am able to do that in Microsoft Edge.
We had the same issue, and there was default configuration in deployment center for my web application, but we are not deploying the code from reposiotry, so we disabled that option. We are deploying web application from visual studio.
Currently the image showing disabled repository options in deployment center of the web application.
Probably because You set CI/CD for your web app deployment.
If you set your deployment with Azure Devops pipelines, and you are doing the yaml file approach, then maybe this is what you are looking for.
firstly you need to set the branch that you want to be triggred when a new commit has been pushed to it.
trigger:
branches:
include:
- refs/heads/staging
variables:
BuildConfiguration: 'Release'
pr: none # Disable pull request triggers.
To make our pipeline a little bit organized, We will work with stages, let's create our Build stage, here I am building a .Net app, you can replace the build task with the build you want.
stages:
- stage: 'Build'
jobs:
- job: 'Build'
pool:
vmImage: 'windows-latest' #The agent that will be used to start this stage
steps:
- task: DotNetCoreCLI#2
displayName: 'dotnet build'
inputs:
command: build
projects: 'MySuperApp/BackgroundService.csproj'
arguments: '--configuration $(BuildConfiguration)'
then I will run dotnet publish, that publishes the application and its dependencies to a folder for deployment to a hosting system.
and here comes the important part, when you create a webjob from azure portal, its files are stored under specific folder.
for Continuous webjobs, it will be stored under \site\wwwroot\app_data\Jobs\Continuous
and for Triggered webjobs it will be under \site\wwwroot\app_data\Jobs\Triggered
- task: DotNetCoreCLI#2
displayName: 'dotnet publish'
inputs:
command: 'publish'
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)/publish_output/App_Data/jobs/continuous/MySuperAppBGS'
projects: 'MySuperApp/BackgroundService.csproj'
publishWebProjects: false
zipAfterPublish: false
modifyOutputPath: false
for me I need to deploy a continuous webjob, as you can see in the arguments within inputs:
--output $(Build.ArtifactStagingDirectory)/publish_output/App_Data/jobs/continuous/MySuperAppBGS'
the dotnet publish will put the generated files under $(Build.ArtifactStagingDirectory)/publish_output/App_Data/jobs/continuous/MySuperAppBGS
then I will zip the content of $(Build.ArtifactStagingDirectory)/publish_output/ which is App_Data/jobs/continuous/MySuperAppBGS
- task: ArchiveFiles#2
displayName: 'Zip Published Files'
inputs:
rootFolderOrFile: '$(Build.ArtifactStagingDirectory)/publish_output'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/MySuperAppAPIBackgroundService.zip'
replaceExistingArchive: true
and publish the content of $(Build.ArtifactStagingDirectory) to drop artifact, which our zip file exist MySuperAppAPIBackgroundService.zip, in order to use it, in the next stage
- task: PublishBuildArtifacts#1
displayName: 'Publish Build artifacts'
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
Here is the second stage, that will deploy our zip file to the web app service, then it will be unzipped leaving
App_Data/jobs/continuous/MySuperAppBGS/* under \site\wwwroot\
- stage: 'Deploy'
jobs:
- deployment: 'Deploy'
environment: 'MySuperAppAPI_BackGround_Staging_env' #just an env variable, that will be used later if you want, give it whatever name you like
strategy:
runOnce:
deploy:
steps:
- task: AzureWebApp#1
displayName: 'Deploy MySuperAppAPIBackgroundService.zip to MySuperAppAPI-Staging-BackgroundService'
inputs:
azureSubscription: 'Your Azure service connection'
appType: 'webApp'
appName: 'MySuperAppAPI-Staging-BackgroundService'
package: '$(Pipeline.Workspace)/drop/MySuperAppAPIBackgroundService.zip'
deploymentMethod: 'zipDeploy'
Note: in the second stage, I didn't call DownloadBuildArtifacts#0 task, because I used deploy: within - deployment: job that auto inject the Download artifact task, and to access the published Artifact from the previous stage, you use $(Pipeline.Workspace) following by the artifact name you provided, in my case it is $(Pipeline.Workspace)/drop
Hope I was clear, for any clarification don't hesitate to ask me.

Visual Studio Team Services Release/Deploy fails - "No package found with specified pattern"

I'm trying to implement continuous integration and continuous deployment to my DEV Azure App Service. I'm using the hosted agent on Visual Studio Team Services. The "Deploy Website to Azure" step on my Release definition keeps failing with the error "No package found with specified pattern". Any ideas?
"More than one package matched with specified pattern. Please restrain the search patern [sic]." error usually occurs when 2 or more packages were found by the task since you entered "xxx\*.zip" in "Package or Folder" setting of the task. So you just need to update it to specify the detailed package name. Similar question here: Deploy azure website and webjobs in same sln using VSO - Error - There can be only one.
And for you original issue, you can also fix it by creating a new build definition with "Visual Studio" selected on "Build" tab and "Azure WebApp" selected on "Deployment" tab. This will create a build definition with required arugments added.
Had the same problem few hours ago. This how I was able to resolve the issue:
Ensure MSBuild arguments in Build solution step are:
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\"
Add step Azure App Service Deployment: ARM
Configure subscription and App Service Name
Package or Folder should be $(build.artifactstagingdirectory)\**\*.zip
Steps:
Azure App Service Deployment Configuration:
if you are using the default azure app service deployment task, add this to end of YAML file:
- task: DotNetCoreCLI#2
displayName: 'dotnet publish $(buildConfiguration)'
inputs:
command: publish
publishWebProjects: True
arguments: '--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: True
- task: PublishBuildArtifacts#1
displayName: 'publish artifacts'
I had the same issue and this worked for me:
# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
variables:
buildConfiguration: 'Release'
steps:
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
- task: DotNetCoreCLI#2
displayName: 'dotnet publish $(buildConfiguration)'
inputs:
command: publish
publishWebProjects: True
arguments: '--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: True
- task: PublishBuildArtifacts#1
displayName: 'publish artifacts'
use the visual designer while creating build pipeline in azure devops,though your code sits at azure repos and github,
then select source
finally pick respective templates to your application
Make sure you didn't tick "Skip artifacts download"

Resources