No artifact created in Azure pipeline - azure

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'

Related

Two .NET core solutions (One containing APIs and another Azure Functions) build/release pipeline not working correctly

I have two solutions in my repository (one AppService (.NET Core API project) and another that is containing Azure Functions).
I am having 2 separate build pipelines and 2 separate release pipelines on Azure DevOps:
UserManagementAPI .yml file (API build pipeline):
trigger:
- dev
pool:
vmImage: 'windows-latest'
variables:
solution: '**/UserManagementAPI.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
displayName: '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"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: DotNetCoreCLI#2
displayName: 'Test'
inputs:
command: test
projects: '**/*Tests/*.csproj'
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI#2
displayName: 'Publish'
inputs:
command: publish
publishWebProjects: true
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: True
- task: PublishPipelineArtifact#1
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
publishLocation: pipeline
artifactName: userManagementAPI
UserManagementAPI.Functions .yml file (Functions build pipeline):
trigger:
- dev
pool:
vmImage: 'windows-latest'
variables:
solution: '**/UserManagementAPI.Functions.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
displayName: 'Build'
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\UserManagement-Function.zip" /p:DeployIisAppPath="Default Web Site"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: DotNetCoreCLI#2
displayName: 'Test'
inputs:
command: test
projects: '**/*Tests/*.csproj'
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI#2
displayName: 'Publish'
inputs:
command: publish
publishWebProjects: true
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: True
- task: PublishPipelineArtifact#1
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
publishLocation: pipeline
artifactName: userManagementAPI-functions
The build pipeline for UserManagementAPI is working just fine, artifact is created correctly, there is a zip file with everything included inside. The release pipeline is working fine as well, basically it's an Azure App Service Deploy task, here is the image:
On the other hand, build pipeline or release pipeline for azure functions are not working correctly, here is the artifact generated from UserManagementAPI.Functions build:
If I download the artifact, UserManagementAPI.zip file is containing all the dlls for UserManagementAPI solution (not the functions) and UserManagement-Function.zip is containing some weird data. Here is what is inside of it:
If I go deep into Content folder:
Here I can see my functions folders and bin folder, bin folder is containing all dlls of the functions (but it's too deep I think, it should be at the top of the zip, not inside Content\D_C\a\1\s\UserManagement.Functions\obj\Release\net6.0\PubTmp\Out\bin).
Each of the functions folders are containing one json file, here is one example:
The artifact files are generated in weird way and weird path in my opinion.
Here is the release pipeline of UserManagementAPI.Functions:
Both build pipelines (API and Functions) are executing successfully, they generate artifacts, release pipeline of UserManagementAPI is working fine but release pipeline of UserManagementAPI-Functions is throwing an error:
##[error]Error: Deployment of msBuild generated package is not supported. Change package format or use Azure App Service Deploy task. /home/azureuser/myagent/_work/r35/a/InternalUsers-Functions/userManagementAPI-functions/UserManagement-Function.zip
I have also found an article on stackoverflow having similar issue, but I couldn't solve it using Fernando Magno's suggestion and Leo Liu's suggestion is confusing to me, how can I have App Service for Azure Function.
To be honest, I'm new to release/build pipelines, especially having same repo with 2 solutions, so any help is appreciated here!

How to deploy code without zip file and inner folders azure devops

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.

Error at executing Azure Pipeline for a .Net Desktop App - Azure DevOps

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.

Does the stage keyword define a Build or Deploy pipeline in Azure DevOps in YAML file

I would like to know if if we consider this block of YAML code if this is already considered a Build and Release pipeline...or we need to define stages to characterise that. This below code works but you don't see the individual stages when you run this. However it does Build and Deploy to Azure in this case. So that's why I ask. I am looking for correct terminology. Is this a Build and Release pipeline or you can't say that and only if I define the stages Build and Release it is one.
Hope this is clear.
# 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'
- task: DownloadBuildArtifacts#0
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'drop'
downloadPath: '$(System.ArtifactsDirectory)'
- task: AzureRmWebAppDeployment#4
inputs:
ConnectionType: 'AzureRM'
appType: 'webApp'
WebAppName:
packageForLinux: '$(System.ArtifactsDirectory)/drop/*.zip'
In YAML, there's no distinction. A pipeline is a pipeline. If it contains stuff that results in software being released, feel free to call it a release pipeline if you want.

Produced artifact has too many layers of folders

I have the following pipeline that builds a ASP.NET Core 5 Web project, but the artifact produced has the following structure
ProjectName.zip
Content
D_C
a
1
s
ProjectName
obj
release
package
PackageTmp
(Finally The actual content) as it should be
archive.xml
parameters.xml
systeminfo.xml
I simply want my zip to be the content of packagetmp without any parent folders
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
feedsToUse: 'select'
vstsFeed: ''myfeed'
- 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
displayName: "Upload Artifacts"
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
You can change the msbuildArgs as below to generate the artifacts as files instead of a zip file. And then you can use Archive files task to zip the artifacts. See below:
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:publishUrl="$(build.artifactstagingdirectory)" /p:PackageAsSingleFile=false /p:SkipInvalidConfigurations=true'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
The msbuildArgs in above example will output the artifacts to folder $(build.artifactstagingdirectory) unzipped.
Then after VSBuild Task. You can add Archive files task to zip the artifacts:
- task: ArchiveFiles#2
displayName: 'Archive task'
inputs:
rootFolderOrFile: '$(Build.ArtifactStagingDirectory)/'
includeRootFolder: false
archiveFile: '$(Build.ArtifactStagingDirectory)/Temp/ProjectName.zip'
Above example will zip the artifacts in $(Build.ArtifactStagingDirectory), and save the zip file in $(Build.ArtifactStagingDirectory)/Temp/ProjectName.zip
Then in the PublishBuildArtifacts task. Set the PathtoPublish to folder $(Build.ArtifactStagingDirectory)/Temp
- task: PublishBuildArtifacts#1
displayName: "Upload Artifacts"
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/Temp'
You should get a zip file with the content of packagetmp only.

Resources