I am trying to deploy a .NET (not .NET Core) web api using Azure DevOps to an Azure Web App. Its a standard issue web api which i have no issues running locally or deploying via Visual Studio Code Azure Deploy extension.
I have the following YAML file. The entire pipeline runs fine without any errors. No errors in the YAML file itself.
# 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)'
- task: PublishBuildArtifacts#1
inputs:
pathToPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: drop
- task: ArchiveFiles#2
inputs:
rootFolderOrFile: '$(Build.ArtifactStagingDirectory)'
includeRootFolder: false
- task: AzureWebApp#1
inputs:
azureSubscription: 'BariBasicConnection'
appName: 'baribasicsapiserverjune21st2020b'
package: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
The web app itself, when I try to load, it gives the following error.
The service is unavailable.
And, when i check the app files via Kudu, I see this in the wwwroot folder, webconfig file.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name = "Site Unavailable" stopProcessing = "true">
<match url = ".*" />
<action type = "CustomResponse" statusCode = "503" subStatusCode = "0" statusReason = "Site Unavailable" statusDescription = "Could not download zip" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
At this point, I am pretty sure, I am not picking up the right folder to deploy or something but Azure DevOps focuses mostly on .NET Core and Node and I am finding it difficult to find .NET specific related solutions.
Took me a good 6 hours of browsing around like some 100 azure doc files but finally got it to work.
A few things I found out.
The main problem was AzureWebApp#1. That is not the deployment component for .NET projects at all.
Further, the packager was already generating a zip file. So, the zip and unzip components in my file is actually not required. but i left it there anyway as it is required for other projects. It took me a while to figure that out.
Here is the full YAML file.
# 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
# commit made to the master branch triggers the pipeline run.
trigger:
- master
# agent pool to run
pool:
vmImage: 'windows-latest'
# standard variables for a asp.net project deployment
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
# .net needs all those nuget packages installed
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
# this is the building of the project
- 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)'
# run the unit tests
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
# publish the build artifacts
# this is where you get the deployment settings
# the deployment zip folder that you can later use for other things.
- task: PublishBuildArtifacts#1
inputs:
pathToPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: drop
# archive the build artifact for later processing
- task: ArchiveFiles#2
inputs:
rootFolderOrFile: '$(Build.ArtifactStagingDirectory)'
includeRootFolder: false
# Extract files
# Extract a variety of archive and compression files such as .7z, .rar, .tar.gz, and .zip
# just extract it as an extra step
- task: ExtractFiles#1
inputs:
archiveFilePatterns: '$(Build.ArtifactStagingDirectory)/**/$(Build.BuildId).zip'
destinationFolder: '$(Build.ArtifactStagingDirectory)/temp1'
cleanDestinationFolder: false
# finally deploy it.
- task: AzureRMWebAppDeployment#4
inputs:
Package: '$(Build.ArtifactStagingDirectory)/projectname.zip'
appType: 'webApp'
ConnectedServiceName: ''
WebAppName: ''
The full repo is also available here - https://github.com/Jay-study-nildana/APIServerDotNetWithSimplePasswordToken/blob/master/azure-pipelines.yml
Related
I'm new to Azure DevOps and trying to configure CI/CD pipelines. Here are the steps that I followed.
Created VM and setup IIS
Created pipeline on Azure devops with Github source code. Here is yml file.
azure-pipelines.yml
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:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: CopyFiles#2
inputs:
contents: 'build/**'
targetFolder: '$(Build.ArtifactStagingDirectory)'
cleanTargetFolder: true
- task: PublishBuildArtifacts#1
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'drop'
Created and configure Deployment groups, and setup agent with auth token
Build and deployment works fine, but there are 2 problems
Build generates artifacts with zip file.
zip file has lot more inner folder where actual executable files are located.
You could use IISWebAppDeploymentOnMachineGroup#0 - IIS web app deploy v0 task in your release pipeline.
Using predefined variable to locate the .zip
$(System.DefaultWorkingDirectory)\**\*.zip
This task supports the .zip file extract.
I'm learning Azure DevOps and I'm stuck with a build pipeline.
The project is a simple .NET Core web app and this is the YAML file
# 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:
- main
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: '**/azpipe.csproj'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\'
platform: '$(buildConfiguration)'
configuration: '$(buildConfiguration)'
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
When I run the pipeline I get error and this is the log
Publish:
azpipe -> D:\a\1\s\obj\Debug\net5.0\PubTmp\Out\
_TransformWebConfig:
No web.config found. Creating 'D:\a\1\s\obj\Debug\net5.0\PubTmp\Out\web.config'
_PrepareForMsDeployPublish:
Creating directory "D:\a\1\a\ \p:platform=Release \p:configuration=Release \p:VisualStudioVersion=17.0 \p:_MSDeployUserAgent=VSTS_ac5aa204-3429-4edf-ae3d-777f0b31c141_build_9_0\".
##[warning]C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk.Publish\targets\PublishTargets\Microsoft.NET.Sdk.Publish.MSDeployPackage.targets(156,5): Warning MSB3191: Unable to create directory "D:\a\1\a\ \p:platform=Release \p:configuration=Release \p:VisualStudioVersion=17.0 \p:_MSDeployUserAgent=VSTS_ac5aa204-3429-4edf-ae3d-777f0b31c141_build_9_0\". The given path's format is not supported.
C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk.Publish\targets\PublishTargets\Microsoft.NET.Sdk.Publish.MSDeployPackage.targets(156,5): warning MSB3191: Unable to create directory "D:\a\1\a\ \p:platform=Release \p:configuration=Release \p:VisualStudioVersion=17.0 \p:_MSDeployUserAgent=VSTS_ac5aa204-3429-4edf-ae3d-777f0b31c141_build_9_0\". The given path's format is not supported. [D:\a\1\s\azpipe.csproj]
The previous error was converted to a warning because the task was called with ContinueOnError=true.
Build continuing because "ContinueOnError" on the task "MakeDir" is set to "true".
and so far whit many of this rows.
I tried several solution found but I cannot get it to work.
Can someone help me?
Thank you!
According to the warning message "Warning MSB3191: Unable to create directory "D:\a\1\a\ \p:platform=Release \p:configuration=Release \p:VisualStudioVersion=17.0 \p:_MSDeployUserAgent=VSTS_ac5aa204-3429-4edf-ae3d-777f0b31c141_build_9_0\". The given path's format is not supported."
It appears that the given path's format is not correct. And in your yaml file, you specified the project but not the solution.
Please specify the solution instead of the project, reference below format:
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildConfiguration)'
configuration: '$(buildConfiguration)'
I'm developing a very simple API in ASP.NET Core for testing purposes.
I have an endpoint at https://localhost:5678/api/Values/addition/{a}/{b} which just adds number A and B and stores the result in a database.
The database is stored on Azure. In local, the application is running well and connects to my Azure SQL Server database successfully. I have hardcoded the connection string to avoid any complexifications which can result in errors. I'll change it later.
I have also created a Release Pipeline on Azure. First, here is the azure-pipelines.yml :
# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/dotnet-core
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:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
The release pipeline is triggered whenever a new push is detected on the master branch :
The job triggered is quite simple, it has a Run On Agent which triggers the deployment of my application to an Azure App Service like that :
steps:
- task: AzureRmWebAppDeployment#4
displayName: 'Deploy To Development'
inputs:
azureSubscription: '{MY SUBSCRIPTION ID}'
appType: webAppLinux
WebAppName: '{MY APP SERVICE NAME}'
deployToSlotOrASE: true
ResourceGroupName: '{MY RESOURCEGROUP NAME, SAME AS THE APP SERVICE}'
The build is successful, all jobs run successfully.
I can now navigate to my app service url https://{MY APP SERVICE NAME}.azurewebsites.net and get the welcome page of Azure :
I assume that at this point, I should be able to navigate to https://{MY APP SERVICE NAME}.azurewebsites.net/api/Values/addition/{a}/{b} and get a response from my API but instead of it, I get an error 404. The api endpoint just doesn't exist.
I've hardcoded everything to avoid system errors like non-acccessible external service, my log stream is also empty, and finally I've used kudu to verify that I have a correct web.config on my application. Everything is, I think, well published.
What am I missing here ?
EDIT 1 :
I've modified my Pipeline as following :
# 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:
- task: DotNetCoreCLI#2
inputs:
command: 'test'
projects: '**/*Tests.csproj'
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
- task: DotNetCoreCLI#2
inputs:
command: 'restore'
projects: '**/*sln'
feedsToUse: 'select'
vstsFeed: '{MY FEED}'
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
publishWebProjects: false
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: true
modifyOutputPath: true
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
It modified my wwwroot/ of the App Service, but it still doesn't work.
I don't think you're actually pushing the zip to the app service (which would explain the 404). The AzureRmWebAppDeployment#4 task you're using requires a Package or packageForLinux parameter if you use the webAppLinux type (scroll down a bit from here), so that it knows what to publish to your app service.
I'm creating my first Pipeline to build a .NET Desktop application. I have added the needed task to my YML file but I'm getting the following error, regarding an assembly that may be missing or not found.
Error Message: "The type or namespace name 'AxAcroPDFLibre' could not be found..."
This is the complete code of my YML file:
# .NET Desktop
# Build and run tests for .NET Desktop or Windows classic desktop solutions.
# Add steps that publish symbols, save build artifacts, and more:
# https://learn.microsoft.com/azure/devops/pipelines/apps/windows/dot-net
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)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: CopyFiles#2
displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
inputs:
SourceFolder: '$(system.defaultworkingdirectory)'
Contents: '**/bin/**'
TargetFolder: '$(build.artifactstagingdirectory)'
condition: succeededOrFailed()
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
condition: succeededOrFailed()
I found this similar question here on StackOverflow, but I have checked my nugget package command and I have it in the build file.
At the end of the process, the job fails.
Right now that's all I've tried since I'm documenting myself on Azure DevOps Pipelines. If you have any recommendations I will appreciate them.
I have tried to Deploy an ARM template from GitHub with Azure DevOps Pipeline (CI/CD). when i click the deploy button I get the following error.
https://developercommunity.visualstudio.com/content/problem/349729/error-no-package-found-with-specified-pattern-dar1.html
##[error]Error: No package found with specified pattern: d:\a\r1\a***.zip
I did as per the suggestion in the following link but doesnt work for me . Added - task: PublishBuildArtifacts#1 to last line of the azure-pipelines.yml file
azure-pipelines.yml
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:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: PublishBuildArtifacts#1
Screenshot
basically this means your package is not being created or is being created in path you are not scanning; try this:
- task: PublishBuildArtifacts#1
inputs:
#pathtoPublish: '$(Build.ArtifactStagingDirectory)'
Azure Devops : ##[error]Error: No package found with specified pattern: d:\a\r1\a***.zip
If you are using "Azure App Service Deploy" task, set the "Package or folder" path to: $(System.DefaultWorkingDirectory)\<YourBuildPipelineName>\<Artifact name>\WebApp.zip.
You can get the path from the log in the Download Artifacts in your release pipeline:
For example:
The value should be in the yellow area.
Alternatively, you can select the .zip file by the option ...:
Hope this helps.