I have a solution containing 2 Azure Functions.
In my build Pipeline I create 2 different zip and "seem" fine to me.
Then I use those zip in my release pipelines, everything seems fine (no error), but when I go in the azure portal, I don't see any function available.
While App Insights only gives me this : Loading functions metadata; 0 functions loaded.
What could be wrong?
build pipeline:
name: Azure Pipelines
steps:
- task: DotNetCoreCLI#2
displayName: 'dotnet build'
inputs:
projects: '**/*.csproj'
- task: DotNetCoreCLI#2
displayName: 'Func1 Publish Zip'
inputs:
command: publish
publishWebProjects: false
projects: '$(System.DefaultWorkingDirectory)/SolutionName/Function1/Function1.csproj'
arguments: '--output publish_output\Function1 --configuration Release'
modifyOutputPath: false
- task: PublishPipelineArtifact#1
displayName: 'Func1 Publish Artifact'
inputs:
targetPath: 'publish_output\Function1\'
artifact: Func1Artifact
- task: DotNetCoreCLI#2
displayName: 'Func2 Publish Zip'
inputs:
command: publish
publishWebProjects: false
projects: '$(System.DefaultWorkingDirectory)/SolutionName/Function2/Function2.csproj'
arguments: '--output publish_output\Function2 --configuration Release'
modifyOutputPath: false
- task: PublishPipelineArtifact#1
displayName: 'Func2 Publish Artifact'
inputs:
targetPath: 'publish_output\Func2\'
artifact: Func2Artifact
1 of the release pipeline :
steps:
- task: AzureFunctionApp#1
displayName: 'Deploy Function 1'
inputs:
azureSubscription: '$(Parameters.AzureSubscription)'
appType: '$(Parameters.AppType)'
appName: '$(Parameters.AppName)'
package: '$(System.DefaultWorkingDirectory)/xxx Build/Func1Artifact'
it is a continuation of this post :
Azure Devops Release pipeline(s) for multiple Azure Functions
EDIT:
log for deploy function:
2021-06-29T08:53:49.6084003Z ##[section]Starting: Deploy Func1 Function
2021-06-29T08:53:49.6208602Z
====
2021-06-29T08:53:49.6209159Z Task : Azure Functions
2021-06-29T08:53:49.6209483Z Description : Update a function app with
.NET, Python, JavaScript, PowerShell, Java based web applications
2021-06-29T08:53:49.6209969Z Version : 1.187.0
2021-06-29T08:53:49.6210422Z Author : Microsoft Corporation
2021-06-29T08:53:49.6211044Z Help :
https://aka.ms/azurefunctiontroubleshooting
2021-06-29T08:53:49.6211592Z
====
2021-06-29T08:53:50.6211817Z Got service connection details for Azure
App Service:'func1-dev'
2021-06-29T08:53:52.6469625Z Deleting App Service Application settings.
Data: ["WEBSITE_RUN_FROM_ZIP","WEBSITE_RUN_FROM_PACKAGE"]
2021-06-29T08:54:17.4575237Z Updated App Service Application settings
and Kudu Application settings.
2021-06-29T08:54:17.5343524Z Package deployment using ZIP Deploy
initiated.
2021-06-29T08:54:38.8090909Z Deploy logs can be viewed at https://func1-
dev.scm.azurewebsites.net/api/deployments/xxxx/log
2021-06-29T08:54:38.8091932Z Successfully deployed web package to App
Service.
2021-06-29T08:55:00.5393032Z Successfully added release annotation to
the Application Insight : func1-dev
2021-06-29T08:55:10.1885833Z Successfully updated deployment History at
https://func1-dev.scm.azurewebsites.net/api/deployments/xxx
2021-06-29T08:55:22.5301509Z App Service Application URL: http://func1-
dev.azurewebsites.net
2021-06-29T08:56:06.1898662Z ##[section]Finishing: Deploy Func1 Function
Related
I work for a small company and we are just starting to get our DevOps pipeline setup. The codebase is about 20 projects in a Visual Studio Solution. Some of these projects' frameworks are .Net 5 and others are .Net Framework 4.8. We are currently in the process of updating but for now we need to use what we have. The following is my attempt at a build pipeline. It runs and I think it works. But I wanted to get more professional opinions on what I can do better because I feel like it is pretty newb.
Here is my yml file:
# 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:
- develop
pool:
vmImage: 'windows-latest'
variables:
solution: '**/MySolution.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
displayName: 'Install NuGet'
- task: NuGetCommand#2
displayName: 'NuGet restore'
inputs:
command: 'restore'
restoreSolution: '$(solution)'
feedsToUse: 'select'
vstsFeed: '6010f35a-7ea3-4aa2-8264-60e3a5f02e6f'
- task: UseDotNet#2
displayName: 'Use .NET Core sdk 5.0.404'
inputs:
packageType: 'sdk'
version: '5.0.404'
includePreviewVersions: true
#Using DotNet and NuGet restore because without doing both the build breaks.
- task: DotNetCoreCLI#2
displayName: 'DotNet Restore'
inputs:
command: 'restore'
projects: '**/*.csproj'
feedsToUse: 'select'
vstsFeed: '6010f35a-7ea3-4aa2-8264-60e3a5f02e6f'
#Specifying older version to work with our older project dependencies.
- task: NodeTool#0
displayName: 'Use Node version 14.x'
inputs:
versionSpec: '14.x'
#The CleanWebsitesPackage lines are weird, I added them because the build was deleting most of the .Net Framework 4.8 project outputs
#when I looked in the logs it showed these steps were the ones doing the deleting.
#By pointing them at nothing it doesn't delete.
- task: VSBuild#1
displayName: 'VS Build'
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"
/p:CleanWebsitesPackageCoreDependsOn=""
/p:CleanWebsitesPackageDependsOn=""'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: ExtractFiles#1
inputs:
archiveFilePatterns: '$(build.artifactStagingDirectory)\WebApp.zip'
destinationFolder: '$(build.artifactStagingDirectory)\WebApp'
cleanDestinationFolder: true
overwriteExistingFiles: true
- task: DeleteFiles#1
inputs:
SourceFolder:
Contents: '(build.artifactStagingDirectory)\WebApp.zip'
- task: PublishPipelineArtifact#1
inputs:
targetPath: '$(build.artifactStagingDirectory)'
# targetPath: '$(Pipeline.Workspace)' #Uncomment to publish entire directory
artifact: 'drop'
publishLocation: 'pipeline'
I would probably keep things simple but here are few suggestions i can think off.
If the scope of this pipeline is to become a multi-stage pipeline in the future then you could utilize stages to define multiple stages of your pipeline
stages:
stage: A
jobs:
job: A1
job: A2
stage: B
jobs:
job: B1
job: B2
Reference: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/stages?view=azure-devops&tabs=yaml
You can use templates to define reusable content, logic, and parameters.
Reference: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azure-devops
I have a problem that I have failed to resolve.
I have a .NET core project that I want to run tests and publish the test coverage on Azure Pipelines.
The problem is: I'm using EF to generate Migrations files. I want to ignore these files from test
but I can't.
Anyone how to do add some arguments to the pipe-lines command to ignore these files? like --exclude Migrations/*.cs
Here is the job in my azure-pipelines.yaml
- job: Testing
steps:
- task: UseDotNet#2
displayName: 'Use .Net Core sdk 3.1.x'
inputs:
version: 3.1.x
- task: DotNetCoreCLI#2
inputs:
command: 'test'
projects: '$(build.sourcesDirectory)/tests/*Tests/*.csproj'
arguments: -c $(BuildConfiguration) --logger trx --collect:"XPlat Code Coverage" --settings:$(build.sourcesDirectory)/src/test.runsettings -- RunConfiguration.DisableAppDomain=true
displayName: 'run tests'
- task: DotNetCoreCLI#2
inputs:
command: custom
custom: tool
arguments: install --tool-path . dotnet-reportgenerator-globaltool
displayName: Install ReportGenerator tool
- script: ./reportgenerator -reports:$(Agent.TempDirectory)/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/coverlet/reports -reporttypes:"Cobertura"
displayName: Create reports
- task: PublishCodeCoverageResults#1
displayName: 'Publish code coverage'
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: $(Build.SourcesDirectory)/coverlet/reports/Cobertura.xml
You're probably looking for -classfilters or -filefilters.
https://github.com/danielpalme/ReportGenerator
I use -classfilter like this, where Foo.Bar.* and Foo.Baz.* is the namespace i want to exclude in the report:
variables:
...
classes-to-exclude-from-coverage: "-Foo.Bar.*;-Foo.Baz.*"
...
- script: ./reportgenerator -reports:$(Agent.TempDirectory)/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/coverlet/reports -reporttypes:"HtmlInline_AzurePipelines;Cobertura;Badges" -assemblyfilters:"-xunit*;" -classfilters:'$(classes-to-exclude-from-coverage)'
displayName: Create reports
First of all I'm building a proof of concept demonstrating a build and deploy (CI/CD0 in Azure Devops.
It is and ASP.NET 4.8 WebApp.
Using the tasks like Download Build Artifacts and Publish Build Artifacts and Deploy Azure Webapp I have no problems. But I read that the aforementioned tasks are being deprecated, but as soon as I use the new Publish PipeLine Artifact Download Pipeline Artifact and then deploy Azure Web App it doesn't work. It publishes and downloads the artifact but at the deploy azure web app stage it says it can't find the artifact. Truth is I have no idea what to fill out there. Googling everything I could find.
The azure deploy task gives me this error: #[error]Error:
No package found with specified pattern: D:\a\1\drop*.*Check i
I see the artifact actually downloads in the Download Pipelineartifact :
Download artifact to: D:\a\1
The actual question would be, what do I fill out the AzureWebApp#1 task with the package: '$(Pipeline.Workspace)/drop/.' (This is wrong but how do I make this right ?)
Very much appreciated
john
Here is my YAML file code:
trigger:
- none
stages:
- stage: Build
pool:
vmImage: 'windows-latest'
jobs:
- job: Build
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: PublishPipelineArtifact#1
inputs:
targetPath: '$(Pipeline.Workspace)'
artifact: 'drop'
publishLocation: 'pipeline'
- stage: Deploy
pool:
vmImage: 'windows-latest'
jobs:
- job: Deploy
steps:
- task: DownloadPipelineArtifact#2
inputs:
buildType: 'current'
artifactName: 'drop'
targetPath: '$(Pipeline.Workspace)'
- task: AzureWebApp#1
inputs:
azureSubscription: 'tofreewebapp'
appType: 'webApp'
appName: 'freewebappdave'
package: '$(Pipeline.Workspace)/drop/*.*'
deploymentMethod: 'auto'
#[error]Error: No package found with specified pattern: D:\a\1\drop*.*
In the DownloadPipelineArtifact task, you downloaded the artifact to the Pipeline.Workspace path, but in the AzureWebApp task, the package path you specified is $(Pipeline.Workspace)/drop/*.*. So the package was not found in the drop folder.
You can change the package path to $(Pipeline.Workspace):
- task: AzureWebApp#1
inputs:
azureSubscription: 'tofreewebapp'
appType: 'webApp'
appName: 'freewebappdave'
package: '$(Pipeline.Workspace)'
deploymentMethod: 'auto'
I hope someone can help me
I am developing an api in dotnet, i am using azure devops and pipelines in yaml.
I have already done my 2e2 test of the api where I basically make real calls to the api that I am developing, in order to test a real user flow within the application.
My question is the following should:
1- Do the 2e2test task before the deployment to my webapp allowing me to know that there is a problem before it is deployed to the resource, but having the problem that I would not be testing with the changes of the present commit (since I would be testing with the previous one because I still I have not deployed the resource)
or
2-do the task 2e2test after the deployment to my webapp, allowing me the tests to be carried out with the changes I made in the commit reflected in the resource and in this way know that what I did gave a problem or not, but having the problem that As the resource was deployed, if there was a problem, it would already be contaminating my webapp.
the yaml I'm working on 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:
- development
pool:
vmImage: 'windows-latest'
steps:
- task: DotNetCoreCLI#2
displayName: 'dotnet publish'
inputs:
command: publish
publishWebProjects: false
projects: '**/ChatbotService/*.csproj'
zipAfterPublish: true
modifyOutputPath: true
- task: DotNetCoreCLI#2
displayName: 'dotnet MockUnitTest'
inputs:
command: test
projects: '**/*Tests/MockUnitTest/*.csproj'
arguments: '--configuration $(buildConfiguration) --collect "Code coverage"'
- task: DotNetCoreCLI#2
displayName: 'dotnet E2ETest'
inputs:
command: test
projects: '**/*Tests/E2ETest/*.csproj'
arguments: '--configuration $(buildConfiguration) --collect "Code coverage"'
- task: AzureRmWebAppDeployment#4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'bla blab bla'
appType: 'webApp'
WebAppName: 'webapp-chatbotservice-dev'
packageForLinux: '$(System.DefaultWorkingDirectory)/ChatbotService/**/*.zip'
AppSettings: '-ASPNETCORE_ENVIRONMENT Development'
You should deploy first and then run your e-2-e tests but not on production. On production you should run smoke tests which are kind of e-2-e tests which test crucial parts of your app without changing state of the app. (of course it makes sense to run them after deployment)
So it could be in high-level like this:
- build stage
- deploy to test env stage
- run e-2-e test
- deploy to prod env stage
- run smoke test
There is always a risk if you run test on not updated env as your test may verify part of app which are not deployed yet.
Good morning,
Sorry to bother you, I have a problem and I have no leads.
I have a pipeline on Azure DevOps where I use coverlet to generate a code coverage report when I use the command "dotnet test".
Indeed, the report is well generated.
At first, in the "Prepare analysis on SonarQube" step, I set the variable "sonar.cs.opencover.reportsPaths="$(Agent.TempDirectory)/coverage.opencover.xml".
And yet the end in my SonarQube there is 0% code coverage... I don't know what to do or any leads...
Thanks
I cannot reproduce above issue. And it is hard to troubleshoot since you did not share your configuration for dotnet test task or sonarqube prepare task.
I created a test project and the coverage was successfully published to my sonarqube server. You can refer to below my steps.
1, create sonarqube server and configure my projectName and projectKey (I use azure sonarqube container instance, check here for details).
2, configure sonarqube service connection in azure devops.
3, create build pipeline. I use yaml pipeline.
In Prepare Analysis Configuration task, I choose to Use standalone scanner, and Mode is Manually provide configure. And I set variable sonar.cs.opencover.reportsPaths="$(Agent.TempDirectory)/coverage.opencover.xml".
Below screenshot is the task's setting in classic ui view.
In my dotnet test task I set the arguments as below, and specifically output the coverage result to $(Agent.TempDirectory)/ folder.
arguments: '--configuration $(buildConfiguration) /p:CollectCoverage=true /p:CoverletOutput=$(Agent.TempDirectory)/ /p:CoverletOutputFormat=opencover'
Below is the full content of my azure-pipelines.yml file.
trigger: none
jobs:
- job: 'Tests'
pool:
vmImage: windows-latest
variables:
buildConfiguration: 'Release'
continueOnError: true
steps:
- task: SonarQubePrepare#4
displayName: 'Prepare analysis on SonarQube'
inputs:
SonarQube: sonarlevi
scannerMode: CLI
configMode: manual
cliProjectKey: myproject2
cliProjectName: myproject2
extraProperties: |
sonar.cs.opencover.reportsPaths="$(Agent.TempDirectory)/coverage.opencover.xml"
- task: DotNetCoreCLI#2
inputs:
command: restore
projects: '**\*.csproj'
- task: DotNetCoreCLI#2
inputs:
command: custom
custom: tool
arguments: install --tool-path . dotnet-reportgenerator-globaltool
displayName: Install ReportGenerator tool
- task: DotNetCoreCLI#2
displayName: Test .NET
inputs:
command: test
projects: '**\*Test*.csproj'
publishTestResults: false
arguments: '--configuration $(buildConfiguration) /p:CollectCoverage=true /p:CoverletOutput=$(Agent.TempDirectory)/ /p:CoverletOutputFormat=opencover'
condition: succeededOrFailed()
- task: SonarQubeAnalyze#4
displayName: 'Run Code Analysis'
- task: SonarQubePublish#4
displayName: 'Publish Quality Gate Result'
I did a lot of things to finally managed to get the coverage working but I think that the problem was the "ProjectGUID" missing in each .csproj of my solution making the projects ignored by SonarQube scanner.
I also upgraded from SonarQube 6.2 to 8.1 at the same time which may have solved the problem.
My steps remained unchanged to make this work.