azure devops build and deploy to app service - azure

I have create an empty project on dev.azure.com
I have cloned the repository on my local computer.
I have run this command in the main folder:
$ dotnet new mvc
I have create this azure-pipelines.yml file:
trigger:
- master
pool:
vmImage: 'windows-latest'
steps:
- task: DotNetCoreCLI#2
inputs:
command: 'restore'
feedsToUse: 'select'
- task: DotNetCoreCLI#2
inputs:
command: 'build'
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
publishWebProjects: true
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'artifact2'
I have add, commit and pushed files on dev.azure.com (on master branch)
I have this warning message:
##[warning]Directory 'd:\a\1\a' is empty. Nothing will be added to build artifact 'artifact2'.
I have create a release pipeline but i get an error:
##[error]Error: No package found with specified pattern: D:\a\r1\a\**\*.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 do not understand what is wrong in my azure-pipelines.yml for artifact production...
Thanks

It seems that there is an issue where the published dlls are placed. Try the yaml below, that I have explicitly set the output directory for the published dlls and zipped the files after publish(that would probably be your next issue). I have also explicitly set in which folder to look for the published folder in order to publish the artifact.
trigger:
- master
pool:
vmImage: 'windows-latest'
steps:
- task: DotNetCoreCLI#2
inputs:
command: 'restore'
feedsToUse: 'select'
- task: DotNetCoreCLI#2
inputs:
command: 'build'
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
publishWebProjects: true
modifyOutputPath: true
arguments: '--configuration $(BuildConfiguration) --output "$(build.artifactstagingdirectory)"'
zipAfterPublish: true
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'artifact2'

Related

No artifact Created during the CI in Azure DevOps

I am trying to create an Azure pipeline for a .NET core project. The build appears to complete with no errors but there is no artifact generated:
Here you can the warnings as well
The YAML definition is below, can anyone see what I'm doing wrong here
trigger:
branches:
include:
- release/*
paths:
include:
- Reeft/Organization/OrganizationService/*
- Reeft/Organization/OrganizationServicePipelines/organization-service-test.yml
pool:
vmImage: 'windows-2022'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
projectName: '**/F11.Web.csproj'
runtime: 'win-x64'
steps:
- task: UseDotNet#2
displayName: 'Use .NET 5 SDK (preview)'
inputs:
packageType: 'sdk'
version: '5.0.100-rc.1.20452.10'
vsVersion: '16.8.0'
includePreviewVersions: true
- task: DotNetCoreCLI#2
inputs:
command: 'restore'
projects: '$(projectName)'
feedsToUse: 'select'
- task: DotNetCoreCLI#2
displayName: Build
inputs:
projects: '$(projectName)'
arguments: '--no-restore'
- task: DotNetCoreCLI#2
displayName: Test
inputs:
command: test
projects: '$(projectName)'
arguments: '-l "console;verbosity=detailed"'
- task: DotNetCoreCLI#2
displayName: 'Publish WebApi'
inputs:
command: publish
publishWebProjects: false
projects: '$(projectName)'
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory) --runtime -r $(runtime)'
- task: CopyFiles#2
inputs:
Contents: '**'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
To generate artifacts you need to add appropriate task Publish Build Artifacts task:
# Publish build artifacts
# Publish build artifacts to Azure Pipelines or a Windows file share
- task: PublishBuildArtifacts#1
inputs:
#pathToPublish: '$(Build.ArtifactStagingDirectory)'
#artifactName: 'drop'
#publishLocation: 'Container' # Options: container, filePath
#targetPath: # Required when publishLocation == FilePath
#parallel: false # Optional
#parallelCount: # Optional
#fileCopyOptions: #Optional
#storeAsTar: false # Optional

CI Triggers on Pipelines in Azure

Im having real issues with a pipeline everytime someone commits or pushes something to a branch on our repo, the pipeline triggers, in following the Microsoft Doc: https://learn.microsoft.com/en-us/azure/devops/pipelines/repos/azure-repos-git?view=azure-devops&tabs=yaml#ci-triggers
Putting in Exclude features on every branch that we have the pipeline will still run when someone does a commit to a local branch even if I have wild carded the branch.
Has anyone been able to get this to work, that the pipeline should only run when there is a commit to Master only and nothing else.
Here is my Code:
trigger:
branches:
include:
- master
exclude:
- CICV/*
- An/*
- Prod/*
- Test/*
- Dev/*
- dev/*
- IN/*
- id/*
- St/*
- tr/*
pool:
vmImage: 'windows-latest'
demands: npm
variables:
System.Debug: false
azureSubscription: 'RunPipelinesInProd'
RG: 'VALUE'
Location: UK South
containername: 'private'
appconnectionname: 'RunPipelinesInProd'
jobs:
- job: job1
displayName: Create And Publish Artifact
pool:
vmImage: vs2017-win2016
steps:
- task: UseDotNet#2
displayName: Use .Net Core 3.1.x SDK
inputs:
packageType: 'sdk'
version: '3.1.x'
- task: DotNetCoreCLI#2
displayName: dotnet restore
inputs:
command: restore
projects: 'Website.csproj'
- task: Npm#1
displayName: 'npm install'
inputs:
workingDir: ClientApp
verbose: false
- task: Npm#1
displayName: 'npm run build'
inputs:
command: 'custom'
workingDir: ClientApp
customCommand: 'build'
- task: DotNetCoreCLI#2
displayName: dotnet build
inputs:
projects: 'Website.csproj'
arguments: '--configuration Release'
- task: DotNetCoreCLI#2
displayName: dotnet Test
inputs:
command: test
projects: 'UnitTests/UnitTests.csproj'
arguments: '--configuration Release'
- task: DotNetCoreCLI#2
displayName: dotnet publish
inputs:
command: publish
projects: 'Website.csproj'
arguments: '--configuration Release --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: true
modifyOutputPath: false
- task: PublishPipelineArtifact#1
displayName: Publish Pipeline Artifact
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
artifact: 'Website'
publishLocation: 'pipeline'
- job: job2
displayName: Create Web App
dependsOn: job1
steps:
# Download Artifact File
- download: none
- task: DownloadPipelineArtifact#2
displayName: 'Download Build Artifacts'
inputs:
patterns: '**/*.zip'
path: '$(Build.ArtifactStagingDirectory)'
# deploy to Azure Web App
- task: AzureWebApp#1
displayName: 'Azure Web App Deploy: nsclassroom-dgyn27h2dfoyo'
inputs:
package: $(Build.ArtifactStagingDirectory)/**/*.zip
azureSubscription: $(azureSubscription)
ConnectedServiceName: $(appconnectionname)
appName: 'VALUE'
ResourceGroupName: $(RG)
You don't need a complex trigger like the one you outlined to trigger the pipeline on pushes to master. The following simple trigger configuration should work:
trigger:
- master
If there's anything in the include section, then only pushes to these branches trigger the build. If you specify both include and exclude sections, then it will try to exclude some subset from the include set - just like in the sample from the docs:
# specific branch build
trigger:
branches:
include:
- master
- releases/*
exclude:
- releases/old*
If the pipeline is still triggered by the push to some other branch, then it must be something else that triggers it.
As mentioned by #yan-sklyraneko in this answer your trigger configuration should be as simple as
trigger:
- master
However the trigger in your YAML file can be overridden in the GUI. Navigate to your pipeline and click Edit then click the ellipses as shown below and select Triggers
On that screen check that the Override the YAML continuous integration trigger from here box is unticked
I solved this in the end, I ended up down the route of managing through the Azure Dev Ops Portal.
It seems that if you try to use YAML to manage this it just doesn't work, but if you do it through the web interface as outlined in Answer 2, then the behaviour is as expected. I think that the Microsoft YAML part is broken for this but I already have three issues open with Microsoft I don't wish to add another one to follow and tag.

No artifact created in Azure pipeline

I am trying to create an Azure pipeline for a .NET Framework project. The build appears to complete with no errors but there is no artifact generated:
The YAML definition is below, can anyone see what I'm doing wrong here?
name: 'App-Api-Dev'
trigger:
batch: true
branches:
include: [ development ]
paths:
include:
- src/App.Api/*
pool:
name: 'Default'
variables:
solution: '**/*.sln'
project: '**/Api.csproj'
buildPlatform: 'x86'
buildConfiguration: 'Release'
stages:
- stage: Build
jobs:
- job: Build
pool:
name: Default
steps:
- task: NuGetToolInstaller#1
displayName: 'Install Nuget'
- task: NuGetCommand#2
displayName: 'Nuget Restore'
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
displayName: 'Build'
inputs:
solution: '$(project)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: PublishSymbols#2
inputs:
SearchPattern: '**/bin/**/*.pdb'
PublishSymbols: false
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifacts'
inputs:
PathtoPublish: $(build.artifactStagingDirectory)
ArtifactName: 'PublishBuildArtifact'
According to the configuration of your publish build artifact task, you are publishing artifacts from $(build.artifactStagingDirectory). However, this directory is purged before each new build and it is empty.
A typical way to use this folder is to publish your build artifacts with the Copy files and Publish build artifacts tasks. You can copy the artifacts you want to publish to this directory before publishing. For example:
- task: CopyFiles#2
inputs:
SourceFolder: '$(Build.SourcesDirectory)'
Contents: '**'
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
If the artifacts you want to publish are ready in some directories, you can also directly use publish build artifact task. For example:
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.SourcesDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
In addition, I suggest you understand the local path and role of each variable.
Build.ArtifactStagingDirectory: The local path on the agent where any artifacts are copied to before being pushed to their destination. For example: c:\agent_work\1\a
Please find more detailed information in this document.
Nothing was copied to the build.artifactstagingdirectory. Try using the newer Publish Pipeline Artifact task. If I have heard correctly this is the right task to use when using Azure DevOps Pipelines for publishing.
- task: PublishPipelineArtifact#1
inputs:
#targetPath: '$(Pipeline.Workspace)'
#artifactName: 'PublishBuildArtifact'

Deploy ASP.NET Core App Service with Azure DevOps path not found

I have a simple build pipeline that triggers on my git commit and is working great.
Here is the .yaml for that process:
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
variables:
buildConfiguration: 'Release'
steps:
- script: dotnet build --configuration $(buildConfiguration)
- task: ArchiveFiles#2
inputs:
rootFolderOrFile: '$(Build.BinariesDirectory)'
includeRootFolder: true
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
replaceExistingArchive: true
displayName: 'dotnet build $(buildConfiguration)'
Then, I tried to make a Release build, but can't get the zip file across to my deploy step. The steps I follow are:
Publish build artifacts
Download build artifacts
Deploy web service
Here is my setup - Overall release pipeline:
Artifact Stage setup as follow:
Here is my 3 tasks in the Stage 1 (Deploy Stage):
Then the 3 tasks's properties:
And here is the error I'm getting, it is with regard to the artefact publish directory:
You should use dotnet publish to create your binaries. The step will also create a zip file. Then to publish the artefacts, use the PublishBuildArtifacts#1 Task. These steps should all be done within a build, not a release.
Here an example:
steps:
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
publishWebProjects: false
projects: '**/*.csproj'
arguments: '-o /app'
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '/app'
ArtifactName: 'drop'
publishLocation: 'Container'
Within the release, you don't need the Publish and Download Build Artefact step since the artefacts are already there (_ISOF). After you run the first Build, you can just select the zip file in the "Package or folder" dropdown.

Azure Pipeline (YAML) deploys an empty solution to my FunctionApp

I'm building a CI-CD azure pipeline with YAML to deploy an azure function app.
Everything works fine, I can even set some properties for the function app, but my function app remains empty.
I downloaded the zip artifact and it looks just fine.
trigger:
- master
variables:
variables:
buildConfiguration: 'Release'
Parameters.RestoreBuildProjects: '**/TestFunction.csproj'
stages:
- stage: Build
jobs:
- job:
pool:
vmImage: 'vs2017-win2016'
continueOnError: false
steps:
- task: DotNetCoreCLI#2
displayName: 'Restore'
inputs:
command: 'restore'
projects: '$(Parameters.RestoreBuildProjects)'
feedsToUse: 'select'
vstsFeed: '/0856b234-f3a6-4052-b5a6-ed9f6ec9c635'
- task: DotNetCoreCLI#2
displayName: Build
inputs:
projects: '$(Parameters.RestoreBuildProjects)'
arguments: '--configuration $(BuildConfiguration)'
- task: DotNetCoreCLI#2
displayName: 'Publish Build'
inputs:
command: publish
arguments: '--configuration $(BuildConfiguration)'
projects: '$(Parameters.RestoreBuildProjects)'
publishWebProjects: false
modifyOutputPath: true
zipAfterPublish: false
- task: ArchiveFiles#2
displayName: "Archive Files"
inputs:
rootFolderOrFile: "$(System.DefaultWorkingDirectory)"
includeRootFolder: false
archiveFile: "$(System.DefaultWorkingDirectory)/build$(Build.BuildId).zip"
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(System.DefaultWorkingDirectory)/build$(Build.BuildId).zip'
ArtifactName: 'drop'
- stage: Deploy
jobs:
# track deployments on the environment
- deployment:
pool:
vmImage: 'vs2017-win2016'
# creates an environment if it doesn’t exist
environment: 'dev'
strategy:
# default deployment strategy
runOnce:
deploy:
steps:
- task: DownloadBuildArtifacts#0
displayName: 'Download Artifacts'
inputs:
buildType: 'current'
downloadType: 'specific'
downloadPath: '$(System.ArtifactsDirectory)'
- task: AzureFunctionApp#1
displayName: 'Azure Function App Deploy: ngproductionfetcherfuncref'
inputs:
azureSubscription: 'Agder Energi Sandbox (1aa9cf92-9d42-49a6-8d31-876ac2dff562)'
appType: functionApp
appName: myFunctionApp
package: '$(System.ArtifactsDirectory)/**/*.zip'
appSettings: '-name0 value0 -name1 value1'
The pipeline is all green:
Got service connection details for Azure App Service:'myFunctionApp'
Updating App Service Application settings. Data: {"WEBSITE_RUN_FROM_PACKAGE":"1"} {"WEBSITE_RUN_FROM_ZIP":{"value":""}}
Updated App Service Application settings and Kudu Application settings.
Package deployment using ZIP Deploy initiated.
Successfully deployed web package to App Service.
Updating App Service Application settings. Data: {"name0":"value0","name1":"value1"} undefined
Updated App Service Application settings and Kudu Application settings.

Resources