Deploying to AppServicePlan Functions from Azure Pipelines takes a long time - azure-devops

'm deploying my application to Azure Functions using the pipeline below.
Deploying to Functions in the Consumption plan completes the deployment stage in less than a minute, but deploying to Functions in the App Service Plan takes more than 10 minutes to deploy.
Why is it taking so long to deploy to Functions in AppServicePlan from Azure Pipelines?
yml
trigger:
branches:
include:
- develop
resources:
- repo: self
variables:
pythonVersion: 3.6
serviceConnetion: 'subscription'
functionAppName: 'functionAppName'
vmImageName: 'ubuntu-latest'
workingDirectory: '$(System.DefaultWorkingDirectory)/'
pool:
vmImage: $(vmImageName)
stages:
- stage: Build
displayName: 'Build stage'
jobs:
- job: Build
displayName: Build
steps:
- bash: |
if [ -f extensions.csproj ]
then
dotnet build extensions.csproj --runtime ubuntu.16.04-x64 --output ./bin
fi
workingDirectory: $(workingDirectory)
displayName: 'Build extensions'
- task: UsePythonVersion#0
displayName: 'Use Python $(pythonVersion)'
inputs:
versionSpec: $(pythonVersion)
- bash: |
python -m venv worker_venv
source worker_venv/bin/activate
pip install -r requirements.txt
workingDirectory: $(workingDirectory)
displayName: 'Install application dependencies'
- task: ArchiveFiles#2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(workingDirectory)'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
- publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
artifact: drop
- stage: Deploy
displayName: 'Develop stage'
dependsOn: Build
condition: succeeded()
jobs:
- deployment: Deploy
displayName: Deploy
environment: 'development'
strategy:
runOnce:
deploy:
steps:
- task: AzureFunctionApp#1
displayName: 'Azure functions app deploy'
inputs:
azureSubscription: '$(serviceConnetion)'
appType:
appName: $(functionAppName)
package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
deploymentMethod: 'runFromPackage'

remote build may be enabled, please disable
it
https://learn.microsoft.com/en-us/azure/azure-functions/functions-deployment-technologies#remote-build

Related

Why i am get error when I trigger my build pipeline No agent found in pool Default which satisfies the specified demands?

I am working in Azure DevOps CICD pipeline. I have created an agent in Default Pool which is a Self-Hosted Agent.
My Agent Details:
Agent.Name: Deployment-Agent
Agent.Version: 2.210.1
Below is my yaml file:
trigger: none
variables:
- name: solution
value: 'MyApp.sln'
- name: buildPlatform
value: 'Any CPU'
- name: buildConfiguration
value: 'Release'
- name: "npm_config_cache"
value: $(Pipeline.Workspace)/.npm
stages:
- stage: StartAzVMAgent
jobs:
- job: MsHostedAgentJobStartAzVM
timeoutInMinutes: 0
pool:
vmImage: 'windows-latest'
steps:
- task: AzureCLI#2
displayName: Azure CLI
inputs:
azureSubscription: "Az-DevOps-AgentManager"
scriptType: ps
scriptLocation: inlineScript
inlineScript: |
az --version
az account show
az vm start --name MyDeployment-Agent --no-wait --resource-group MyDeployment
- stage: __default
jobs:
- job: Job
timeoutInMinutes: 0
pool:
name: Default
demands:
- Agent.Name -equals Deployment-Agent
steps:
- task: Npm#1
displayName: Install Node dependencies (packages)
inputs:
command: custom
customCommand: install --save --legacy-peer-deps
workingDir: 'MyApp.WebUI\MyClientApp'
- task: Npm#1
displayName: Install Node dependencies (packages)
inputs:
command: custom
customCommand: install sweetalert2 file-saver
workingDir: 'MyApp.WebUI\MyClientApp'
- task: Cache#2
displayName: Cache npm
inputs:
key: 'npm | "$(Agent.OS)" | **/package-lock.json'
restoreKeys: |
npm | "$(Agent.OS)"
path: $(npm_config_cache)
- script: npm ci
- task: CmdLine#2
displayName: Building Client App
inputs:
script: node --max_old_space_size=8192 node_modules/#angular/cli/bin/ng build --configuration production --aot --build-optimizer=true --common-chunk=true --named-chunks=false --optimization=true --vendor-chunk=true --progress=true
workingDirectory: 'MyApp.WebUI\MyClientApp'
- task: CopyFiles#2
displayName: 'Copy Client Project'
inputs:
Contents: |
MyApp.WebUI\MyClientApp\dist\**
TargetFolder: '$(build.artifactstagingdirectory)/client'
flattenFolders: false
CleanTargetFolder: true
- task: UseDotNet#2
displayName: Use .NET 6.0
inputs:
packageType: 'sdk'
version: '6.0.x'
installationPath: $(Agent.ToolsDirectory)/dotnet
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
publishWebProjects: true
zipAfterPublish: true
arguments: '--output $(build.artifactstagingdirectory)/api'
- task: CmdLine#2
displayName: Create EF Scripts
inputs:
script: |
dotnet ef migrations add FreshDb_08022021 -c MyAppDbcontext
dotnet ef migrations script --idempotent --output migrations.sql --project MyApp.Persistence/MyApp.Persistence.csproj --context MyAppDbContext
- task: CopyFiles#2
displayName: 'Copy EF Scripts to Staging'
inputs:
Contents: "**\\migrations.sql \n"
TargetFolder: '$(build.artifactstagingdirectory)'
flattenFolders: true
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
- stage: StoptAzVMAgent
dependsOn: __default
condition: always()
jobs:
- job: MsHostedAgentJobStopAZVm
timeoutInMinutes: 0
pool:
vmImage: 'windows-latest'
steps:
- task: AzureCLI#2
displayName: Azure CLI
inputs:
azureSubscription: "Az-DevOps-AgentManager"
scriptType: ps
scriptLocation: inlineScript
inlineScript: |
az --version
az account show
az vm deallocate --name MyDeployment-Agent --no-wait --resource-group MyDeployment
However i am getting the below error even when my agent is enabled and running.
#Error: No agent found in pool Default which satisfies the specified demands: Use_for -equals Deployment-Agent, npm, Agent.Version -gtVersion 2.182.1
Can I know from were does it takes this 2.182.1 as version as my agent version is higher than this but still it takes previous version and gives me error? Can anyone please help me on this as I am new to azure cicd?
According to the error message, please try the following steps:
Check the User capability of the "Use_for" in your agent.
Install the NPM in your agent and then restart the agent to scan the NPM.
For more information, you could refer to:https://learn.microsoft.com/en-us/azure/devops/pipelines/process/demands?view=azure-devops&tabs=yaml
And install the NPM:https://docs.npmjs.com/downloading-and-installing-node-js-and-npm

How to use pipeline caching in Azure devOps to cache Angular and .NET dependencies?

I am working on build pipeline in Azure DevOps. I have Angular 14 and .NET 6.0 applications in my yaml. Below is my yaml. Everything is working fine except when I am using cache in my step.
I have 2 questions:
Is it necessary to run npm install and other npm dependencies every time I do build pipeline?
What is the issue for my below yaml file when I use the Cache#2 step?
YAML:
variables:
- name: solution
value: 'MyApp.sln'
- name: buildPlatform
value: 'Any CPU'
- name: buildConfiguration
value: 'Release'
- name: "npm_config_cache"
value: $(Pipeline.Workspace)/.npm
stages:
- stage: StartAzVMAgent
jobs:
- job: MsHostedAgentJobStartAzVM
timeoutInMinutes: 0
pool:
vmImage: 'windows-latest'
steps:
- task: AzureCLI#2
displayName: Azure CLI
inputs:
azureSubscription: "Az-DevOps-AgentManager"
scriptType: ps
scriptLocation: inlineScript
inlineScript: |
az --version
az account show
az vm start --name MyDeployment-Agent --no-wait --resource-group MyDeployment
- stage: __default
jobs:
- job: Job
timeoutInMinutes: 0
pool:
name: Default
demands:
- Use_for -equals myAgentMachine
steps:
- task: Npm#1
displayName: Install Node dependencies (packages)
inputs:
command: custom
customCommand: install --save --legacy-peer-deps
workingDir: 'MyApp.WebUI\MyClientApp'
- task: Npm#1
displayName: Install Node dependencies (packages)
inputs:
command: custom
customCommand: install sweetalert2 file-saver
workingDir: 'MyApp.WebUI\MyClientApp'
- task: Cache#2
displayName: Cache npm
inputs:
key: 'npm | "$(Agent.OS)" | **/package-lock.json'
restoreKeys: |
npm | "$(Agent.OS)"
path: $(npm_config_cache)
- script: npm ci
- task: CmdLine#2
displayName: Building Client App
inputs:
script: node --max_old_space_size=8192 node_modules/#angular/cli/bin/ng build --configuration production --aot --build-optimizer=true --common-chunk=true --named-chunks=false --optimization=true --vendor-chunk=true --progress=true
workingDirectory: 'MyApp.WebUI\MyClientApp'
- task: CopyFiles#2
displayName: 'Copy Client Project'
inputs:
Contents: |
MyApp.WebUI\MyClientApp\dist\**
TargetFolder: '$(build.artifactstagingdirectory)/client'
flattenFolders: false
CleanTargetFolder: true
- task: UseDotNet#2
displayName: Use .NET 6.0
inputs:
packageType: 'sdk'
version: '6.0.x'
installationPath: $(Agent.ToolsDirectory)/dotnet
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
publishWebProjects: true
zipAfterPublish: true
arguments: '--output $(build.artifactstagingdirectory)/api'
- task: CmdLine#2
displayName: Create EF Scripts
inputs:
script: |
dotnet ef migrations add FreshDb_08022021 -c MyAppDbcontext
dotnet ef migrations script --idempotent --output migrations.sql --project MyApp.Persistence/MyApp.Persistence.csproj --context MyAppDbContext
- task: CopyFiles#2
displayName: 'Copy EF Scripts to Staging'
inputs:
Contents: "**\\migrations.sql \n"
TargetFolder: '$(build.artifactstagingdirectory)'
flattenFolders: true
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
- stage: StoptAzVMAgent
dependsOn: __default
condition: always()
jobs:
- job: MsHostedAgentJobStopAZVm
timeoutInMinutes: 0
pool:
vmImage: 'windows-latest'
steps:
- task: AzureCLI#2
displayName: Azure CLI
inputs:
azureSubscription: "Az-DevOps-AgentManager"
scriptType: ps
scriptLocation: inlineScript
inlineScript: |
az --version
az account show
az vm deallocate --name MyDeployment-Agent --no-wait --resource-group MyDeployment
Error:
npm ERR! The npm ci command can only install with an existing package-lock.json or
npm ERR! npm-shrinkwrap.json with lockfileVersion >= 1. Run an install with npm#5 or
npm ERR! later to generate a package-lock.json file, then try again.
Not really an expert on Azure Pipelines, but this link might help: https://learn.microsoft.com/en-us/azure/devops/pipelines/release/caching?view=azure-devops#nodejsnpm
Basically, you have to have a package-lock.json file in your project for the caching to work.

No package found with specified pattern in AzureRmWebAppDeployment#4

I have the following Azure Pipelines jobs:
- job: Publish
pool:
vmImage: 'Ubuntu 16.04'
steps:
- task: UseDotNet#2
displayName: Setup
inputs:
packageType: sdk
version: 3.1.x
- task: DotNetCoreCLI#2
displayName: Publish
inputs:
command: publish
publishWebProjects: false
projects: 'src/**/*.csproj'
arguments: '--configuration staging --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: true
- task: PublishPipelineArtifact#1
displayName: Export
inputs:
artifact: 'Staging'
targetPath: '$(Build.ArtifactStagingDirectory)'
- deployment: Deploy
dependsOn: Publish
pool:
vmImage: Ubuntu-16.04
environment: staging
strategy:
runOnce:
deploy:
steps:
- task: DownloadPipelineArtifact#2
displayName: Import
inputs:
artifact: 'Staging'
- task: AzureRmWebAppDeployment#4
displayName: Api
inputs:
connectedServiceName: '$(azure.subscription)'
webAppKind: 'webApp'
webAppName: 'bityond-demo-api'
package: '$(Build.ArtifactStagingDirectory)/Api.zip'
removeAdditionalFilesFlag: true
When I run the pipeline the following tasks are successful:
Setup
Publish
Export
Import
Then on the last task, "Api" - AzureRmWebAppDeployment#4, I get the error:
##[error]Error: No package found with specified pattern: /home/vsts/work/1/a/Api.zip<br/>Check if the package mentioned in the task is published as an artifact in the build or a previous stage and downloaded in the current job.
I checked and the artifacts are available and I am able to download them.
And the Import task is successful so what I am missing?
Try to specify destination directory for the imported artifact:
- task: DownloadPipelineArtifact#2
inputs:
artifact: 'Staging'
targetPath: '$(Build.ArtifactStagingDirectory)'
If not specified, artifacts by defaults are downloaded into $(Pipeline.Workspace) directory that is equal to /home/vsts/work/1. And for the AzureRmWebAppDeployment#4 task you are looking for artifacts at $(Build.ArtifactStagingDirectory) directory (equal to /home/vsts/work/1/a)

Why are the Changes and Workitems pages empty under an Environment in a multi-stage Azure Devops pipline?

I created a yaml-based, multi-stage pipeline in Azure DevOps.
variables:
versionPrefix: '7.1.0.'
versionRevision: $[counter(variables['versionPrefix'], 100)]
version: $[format('{0}{1}',variables['versionPrefix'],variables['versionRevision'])]
solution: '**/product.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Debug'
name: $(version)_$(Date:yyyyMMdd)$(Rev:.r)
stages:
- stage: Build
pool: Default
jobs:
- job: Build
displayName: Build
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VersionAssemblies#2
displayName: Version Assemblies
inputs:
Path: '$(Build.SourcesDirectory)'
VersionNumber: '$(version)'
InjectVersion: true
FilenamePattern: 'AssemblyInfo.*'
OutputVersion: 'OutputedVersion'
- task: VSBuild#1
displayName: Build product
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
maximumCpuCount: true
- stage: Deploy
dependsOn: Build
pool: Default
jobs:
- deployment: Deployment
displayName: DeployA
environment: 7-1-0
strategy:
runOnce:
deploy:
steps:
- task: PowerShell#2
inputs:
targetType: 'inline'
script: |
Write-Host "Deployed"
As shown above, the pipeline includes a deployment stage that references an environment named '7-1-0'. After the pipeline runs, a deployment is displayed in the UI for that environment. However, under that environment both the Changes and Workitems pages are empty. I confirmed there are new changes that have not previously been deployed to this environment. Why?
Note the deployment stage doesn't actually do anything. We're doing the actual deployment manually, but were hoping to track the changes to the environment via DevOps. Also, we haven't defined any resources for the environment. I couldn't find anything stating it was required to have a resource defined for traceability of commits and work items.
UPDATE 1
Per #Leo-Liu-MSFT suggestion below, I updated the pipeline to publish an artifact. Note that the build runs on a self-hosted agent. However, I'm still not getting any results in Environment Changes and Workitems.
variables:
versionPrefix: '7.1.0.'
versionRevision: $[counter(variables['versionPrefix'], 100)]
version: $[format('{0}{1}',variables['versionPrefix'],variables['versionRevision'])]
solution: '**/product.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Debug'
name: $(version)_$(Date:yyyyMMdd)$(Rev:.r)
stages:
- stage: Build
pool: Default
jobs:
- job: Build
displayName: Build
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VersionAssemblies#2
displayName: Version Assemblies
inputs:
Path: '$(Build.SourcesDirectory)'
VersionNumber: '$(version)'
InjectVersion: true
FilenamePattern: 'AssemblyInfo.*'
OutputVersion: 'OutputedVersion'
- task: VSBuild#1
displayName: Build product
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
maximumCpuCount: true
- task: PowerShell#2
inputs:
targetType: 'inline'
script: |
New-Item -Path '$(build.artifactstagingdirectory)' -Name "testfile1.txt" -ItemType "file" -Value "Hello, DevOps!" -force
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'FilePath'
TargetPath: 'C:\a\p\\$(Build.DefinitionName)\\$(Build.BuildNumber)'
- stage: Deploy
dependsOn: Build
pool: Default
jobs:
- deployment: Deployment
displayName: DeployA
environment: 7-1-0
strategy:
runOnce:
deploy:
steps:
- task: PowerShell#2
inputs:
targetType: 'inline'
script: |
Write-Host "Deployed"
UPDATE 2
Per follow up suggestion from #Leo-Liu-MSFT, I created the following attempted publishing the artifact to Azure. I also simplified the yaml to use a Microsoft Hosted Agent. Note I did have the issue described here which is why I configured the deployment task they way I did with 'download: none'. I'm still not getting any Changes or Workitems in the environment.
variables:
ArtifactName: drop
stages:
- stage: Build
jobs:
- job: Build
displayName: Build
pool:
vmImage: ubuntu-latest
steps:
- task: CopyFiles#2
displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
inputs:
SourceFolder: '$(System.DefaultWorkingDirectory)/Build'
targetFolder: '$(build.artifactstagingdirectory)'
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'
inputs:
ArtifactName: $(ArtifactName)
- stage: Deploy
dependsOn: Build
pool:
vmImage: ubuntu-latest
jobs:
- deployment: Deployment
displayName: DeployA
environment: 7-1-0
strategy:
runOnce:
deploy:
steps:
- download: none
- task: DownloadBuildArtifacts#0
inputs:
artifactName: $(ArtifactName)
buildType: 'current'
downloadType: 'single'
downloadPath: '$(System.ArtifactsDirectory)'
FINAL UPDATE
Here's the working YAML. The final trick was to set download to current and specify the artifact name.
variables:
ArtifactName: drop
stages:
- stage: Build
jobs:
- job: Build
displayName: Build
pool:
vmImage: ubuntu-latest
steps:
- task: CopyFiles#2
displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
inputs:
SourceFolder: '$(System.DefaultWorkingDirectory)/Build'
targetFolder: '$(build.artifactstagingdirectory)'
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'
inputs:
ArtifactName: $(ArtifactName)
- stage: Deploy
dependsOn: Build
pool:
vmImage: ubuntu-latest
jobs:
- deployment: Deployment
displayName: DeployA
environment: 7-1-0
strategy:
runOnce:
deploy:
steps:
- download: current
artifact: $(ArtifactName)
Why are the Changes and Workitems pages empty under an Environment in a multi-stage Azure Devops pipline?
You need to add publish build Artifacts task to publish build artifacts to Azure Pipelines.
Azure devops track the changes and workitems via REST API, then Azure devops passes this information to other environments by transferring files.
So, we need to publish the artifact to the Azure Pipelines so that the deploy stage could get those info when it is getting source.
As test, I just add the copy task and publish build artifact task in the build stage, like:
stages:
- stage: Build
jobs:
- job: Build
displayName: Build
pool:
vmImage: ubuntu-latest
steps:
- task: CopyFiles#2
displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
inputs:
SourceFolder: '$(System.DefaultWorkingDirectory)'
targetFolder: '$(build.artifactstagingdirectory)'
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact: drop'
- stage: Deploy
dependsOn: Build
pool:
vmImage: ubuntu-latest
jobs:
- deployment: Deployment
displayName: DeployA
environment: 7-1-0
strategy:
runOnce:
deploy:
steps:
- task: PowerShell#2
inputs:
targetType: 'inline'
script: |
Write-Host "Deployed"
The result:
Update:
I had to make a few updates to deal with an issue downloading the
artifact. Still not getting any Changes or Workitems on the
environment. I do appreciate your help!
That because you are disable the built-in download task instead of using DownloadBuildArtifacts task, which task do not have feature to fetch the commits and work items.
- download: none
You need delete above in your YAML. As I test your updated YAML without - download: none, it works fine.
Hope this helps.

Can't get Azure DevOps Release Pipelines to when I include Code Coverage

So I'm trying to set up a YAML for the new unified build and release pipelines, but running to problems when I publish code coverage results to the build...
The error I get, when I include code coverage reporting, is:
Job Job1: Step Download_Code Coverage Report_870 has an invalid name. Valid names may only contain alphanumeric characters and '_' and may not start with a number.
When I set it up like this, it works, but I don't get code coverage results:
# 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
variables:
buildConfiguration: 'Release'
system.debug: true
stages:
- stage: BuildAndDeploy
displayName: Test
jobs:
- job: Quality
displayName: Get Test Coverage and Code Quality
pool:
vmImage: 'ubuntu-latest'
steps:
# Install the latest version of the dotnet sdk
- task: DotNetCoreInstaller#0
displayName: 'Use .NET Core sdk 2.2.103'
inputs:
version: 2.2.103
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
- script: dotnet test --configuration $(buildConfiguration) --logger trx --no-build
displayName: 'dotnet test --configuration $(buildConfiguration) --logger trx --no-build'
- task: PublishTestResults#2
inputs:
testRunner: VSTest
testResultsFiles: 'test/**/*.trx'
- task: DotNetCoreCLI#2
displayName: Package Artifact
inputs:
command: 'publish'
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: True
publishWebProjects: true
feedsToUse: 'select'
versioningScheme: 'off'
- task: PublishPipelineArtifact#0
inputs:
artifactName: 'FakeApiServer'
targetPath: '$(Build.ArtifactStagingDirectory)/FakeApi.Server.AspNetCore.zip'
- stage: DeployTest
dependsOn: BuildAndDeploy
condition: and(succeeded(), not(eq(variables['Build.SourceBranch'], 'refs/heads/master')))
displayName: Deploy To Test
jobs:
- deployment: DeployToTest
environment: Testing
pool:
vmImage: 'ubuntu-latest'
strategy:
runOnce:
deploy:
steps:
- task: DownloadPipelineArtifact#1
inputs:
buildType: 'current'
artifactName: 'FakeApiServer'
targetPath: '$(System.ArtifactsDirectory)'
- task: AzureRmWebAppDeployment#4
displayName: Deploy to https://fake-api-test.azurewebsites.com
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'Fake API Personal Azure Subscription'
appType: 'webApp'
WebAppName: 'fake-api-test'
Package: $(System.ArtifactsDirectory)/*.zip
enableCustomDeployment: true
DeploymentType: 'zipDeploy'
- stage: DeployProd
dependsOn: BuildAndDeploy
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
displayName: Deploy To Prod
jobs:
- deployment: DeployToProd
environment: Production
pool:
vmImage: 'ubuntu-latest'
strategy:
runOnce:
deploy:
steps:
- task: DownloadPipelineArtifact#1
inputs:
buildType: 'current'
artifactName: 'FakeApiServer'
targetPath: '$(System.ArtifactsDirectory)'
- task: AzureRmWebAppDeployment#4
displayName: Deploy to https://fake-api.azurewebsites.com
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'Fake API Personal Azure Subscription'
appType: 'webApp'
WebAppName: 'fake-api'
Package: $(System.ArtifactsDirectory)/*.zip
enableCustomDeployment: true
DeploymentType: 'zipDeploy'
But when I include running and reporting code coverage, the deploy stage fails:
# 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
variables:
buildConfiguration: 'Release'
system.debug: true
stages:
- stage: BuildAndDeploy
displayName: Test
jobs:
- job: Quality
displayName: Get Test Coverage and Code Quality
pool:
vmImage: 'ubuntu-latest'
steps:
# Install the latest version of the dotnet sdk
- task: DotNetCoreInstaller#0
displayName: 'Use .NET Core sdk 2.2.103'
inputs:
version: 2.2.103
- script: dotnet tool install --global coverlet.console
displayName: 'Install coverlet'
- script: dotnet tool install -g dotnet-reportgenerator-globaltool
displayName: 'install reportgenerator'
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
- script: dotnet test --configuration $(buildConfiguration) /p:Exclude="[xunit*]*" /p:CollectCoverage=true /p:CoverletOutputFormat=\"opencover,cobertura\" --logger trx --no-build
displayName: 'dotnet test --configuration $(buildConfiguration) /p:Exclude="[xunit*]*" /p:CollectCoverage=true /p:CoverletOutputFormat="opencover,cobertura" --logger trx --no-build'
- script: reportgenerator -reports:test/**/coverage.cobertura.xml -targetdir:coveragereport -reporttypes:"HtmlInline_AzurePipelines;Cobertura"
displayName: 'reportgenerator -reports:test/**/coverage.cobertura.xml -targetdir:coveragereport -reporttypes:"HtmlInline_AzurePipelines;Cobertura"'
- task: PublishTestResults#2
inputs:
testRunner: VSTest
testResultsFiles: 'test/**/*.trx'
- task: PublishCodeCoverageResults#1
displayName: 'Publish code coverage'
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(Build.SourcesDirectory)/coveragereport/Cobertura.xml'
- task: DotNetCoreCLI#2
displayName: Package Artifact
inputs:
command: 'publish'
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: True
publishWebProjects: true
feedsToUse: 'select'
versioningScheme: 'off'
- task: PublishPipelineArtifact#0
inputs:
artifactName: 'FakeApiServer'
targetPath: '$(Build.ArtifactStagingDirectory)/FakeApi.Server.AspNetCore.zip'
- stage: DeployTest
dependsOn: BuildAndDeploy
condition: and(succeeded(), not(eq(variables['Build.SourceBranch'], 'refs/heads/master')))
displayName: Deploy To Test
jobs:
- deployment: DeployToTest
environment: Testing
pool:
vmImage: 'ubuntu-latest'
strategy:
runOnce:
deploy:
steps:
- task: DownloadPipelineArtifact#1
inputs:
buildType: 'current'
artifactName: 'FakeApiServer'
targetPath: '$(System.ArtifactsDirectory)'
- task: AzureRmWebAppDeployment#4
displayName: Deploy to https://fake-api-test.azurewebsites.com
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'Fake API Personal Azure Subscription'
appType: 'webApp'
WebAppName: 'fake-api-test'
Package: $(System.ArtifactsDirectory)/*.zip
enableCustomDeployment: true
DeploymentType: 'zipDeploy'
- stage: DeployProd
dependsOn: BuildAndDeploy
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
displayName: Deploy To Prod
jobs:
- deployment: DeployToProd
environment: Production
pool:
vmImage: 'ubuntu-latest'
strategy:
runOnce:
deploy:
steps:
- task: DownloadPipelineArtifact#1
inputs:
buildType: 'current'
artifactName: 'FakeApiServer'
targetPath: '$(System.ArtifactsDirectory)'
- task: AzureRmWebAppDeployment#4
displayName: Deploy to https://fake-api.azurewebsites.com
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'Fake API Personal Azure Subscription'
appType: 'webApp'
WebAppName: 'fake-api'
Package: $(System.ArtifactsDirectory)/*.zip
enableCustomDeployment: true
DeploymentType: 'zipDeploy'
Again, the error I'm getting is:
Job Job1: Step Download_Code Coverage Report_870 has an invalid name. Valid names may only contain alphanumeric characters and '_' and may not start with a number.
I was at Build 2019 and talked to the Azure DevOps folks at their booth, and they seemed to think it was likely an error in the system, but I still haven't heard back from them, so I figured I would see if anyone here had any ideas.
The really weird part is I'm never telling it to download the code coverage report artifact... it's just deciding to download it all on it's own, and failing before it ever gets to the download pipeline artifact step I defined.
You could try out the ReportGenerator extension: https://marketplace.visualstudio.com/items?itemName=Palmmedia.reportgenerator (at least is saves some build time as you do not need to install it during build)
Also I have encountered several build issues today and seems to be tied to the usage of vmImage set to 'ubuntu-latest'.
What I see happening is that on some builds the filesystem wil look like this:
/home/vsts/agents/2.150.3/d:\a/1/s/
Whereas it should be:
/home/vsts/work/1/s/
After switching to 'Ubuntu 16.04' it seems to be back to normal.
i have the same issue , but i think its related to deployment job , when i use standard job with the same steps - issue didn't appear. Also i have noticed that my deployment job run on Server agent even if pool: vmImage: ubuntu-latest is configured