Produced artifact has too many layers of folders - azure

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.

Related

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.

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'

Azure Devops : ##[error]Error: No package found with specified pattern: d:\a\r1\a\**\*.zip

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.

Resources