Nuget package Version Issue for YAML - azure-devops

I am trying to get the Nuget file generated in the drop folder to have a name like this - Project.1.0.1-prerelease-2021-05-10.nupkg. But the output of this YAML in the build pipeline is Project.0.1.0.nupkg. What is not correct here? I have tried too many combinations but it keeps generating this in the drop folder.
The csproj file does have a version prefix field like this though
YAML
# 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
name: $(BuildDefinitionName)_$(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)
trigger:
- main
pool:
vmImage: windows-latest
variables:
buildConfiguration: 'Release'
steps:
- task: DotNetCoreCLI#2
displayName: 'Restore Dependencies'
inputs:
command: 'restore'
projects: '**/*.csproj'
vstsFeed: '9fc2d633-cc8b-49be-a58d-abb9adf6a2c9'
- task: DotNetCoreCLI#2
displayName: 'Debug Build'
inputs:
command: 'build'
projects: '**/*.csproj'
configuration: debug
- task: DotNetCoreCLI#2
displayName: 'Pack Pre Release'
inputs:
command: 'pack'
packagesToPack: '**/Project.csproj'
includesymbols: true
includesource: true
packDirectory: '$(build.artifactstagingdirectory)/release'
arguments: '--configuration debug'
versioningScheme: byPrereleaseNumber
majorVersion: 1
minorVersion: 0
patchVersion: 1
- task: CopyFiles#2
displayName: 'Copy Artifacts'
inputs:
Contents: '**\*.nupkg'
TargetFolder: '$(build.artifactstagingdirectory)'
- task: PublishBuildArtifacts#1
displayName: 'Publish artifacts'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'

Ok so got it working by changing this
- task: DotNetCoreCLI#2
displayName: 'Pack Pre Release'
inputs:
command: 'pack'
packagesToPack: '**/Project.csproj'
includesymbols: true
includesource: true
packDirectory: '$(build.artifactstagingdirectory)/release'
arguments: '--configuration debug'
versioningScheme: byPrereleaseNumber
majorVersion: 1
minorVersion: 0
patchVersion: 1
to this
- task: DotNetCoreCLI#2
displayName: 'Pack pre-release package'
inputs:
command: 'custom'
projects: '**/Project.csproj'
custom: 'pack'
arguments: '--version-suffix "pre-release-"$(Build.BuildNumber) --output $(build.artifactstagingdirectory)/debug'
And also right at the top, I changed the name variable to
name: $(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)
And that gives me this package.

Related

Error Testing DotNet Project on Azure Devops

I'm trying to setup a build on azure devops to suppress flaky tests and continue going through the the tasks, but the test section that I got from the documentation fails regardless of what I try and do
I setup my test section based off of this document
https://learn.microsoft.com/en-us/azure/devops/pipelines/ecosystems/dotnet-core?view=azure-devops&tabs=dotnetfive
specifically lifting this block
steps:
# ...
# do this after your tests have run
- script: dotnet test <test-project> --logger trx
- task: PublishTestResults#2
condition: succeededOrFailed()
inputs:
testRunner: VSTest
testResultsFiles: '**/*.trx'
I get this error message
##[error]Bash exited with code '1'.
and my azure pipeline looks like this
parameters:
- name: solution
type: string
- name: buildPlatform
type: string
- name: buildConfiguration
type: string
steps:
- task: UseDotNet#2
inputs:
version: '5.0.x'
packageType: 'sdk'
- task: DotNetCoreCLI#2
displayName: 'dotnet restore'
inputs:
command: restore
projects: ${{ parameters.solution }}
feedsToUse: select
- task: DotNetCoreCLI#2
displayName: 'dotnet build'
inputs:
command: build
includeNuGetOrg: true
projects: ${{ parameters.solution }}
arguments: '--configuration ${{ parameters.buildConfiguration }}'
- script: dotnet test ${{ parameters.solution }} --logger trx
- task: PublishTestResults#2
condition: succeededOrFailed()
inputs:
testRunner: VSTest
testResultsFiles: '**/*.trx'
- task: CopyFiles#2
displayName: 'copy build'
inputs:
sourceFolder: '$(Build.SourcesDirectory)'
Contents: |
**/*
!.git/**/*
targetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts#1
displayName: 'publish artifact'
inputs:
pathToPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: drop
- task: ArchiveFiles#2
displayName: 'zip nuget packages'
inputs:
rootFolderOrFile: '$(Build.ArtifactStagingDirectory)/_nupkgs'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/NugetPackages.zip'
replaceExistingArchive: true
- task: PublishBuildArtifacts#1
displayName: 'publish nuget packages'
inputs:
pathToPublish: '$(Build.ArtifactStagingDirectory)/NugetPackages.zip'
artifactName: nugetPackages

Nuget package not available in artifact

I am trying to push private nuget package via azure pipeline. There is no error but i cant see artifact being published in my feed. Here is my yml file. What am i doing wrong here or what can i add?
name: $(BuildDefinitionName)_$(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
buildConfiguration: 'Release'
version.MajorMinor: '4.0'
version.Revision: $[counter(variables['version.MajorMinor'], 0)]
versionNumber: '$(version.MajorMinor).$(version.Revision)'
steps:
- task: CmdLine#2
inputs:
script: 'dir'
displayName: 'dotnet build $(buildConfiguration)'
- task: DotNetCoreCLI#2
displayName: 'dotnet build'
inputs:
command: 'build'
arguments: '--configuration $(buildConfiguration)'
projects: 'MyProj.csproj'
- task: PowerShell#2
displayName: Set the name of the build (i.e. the Build.BuildNumber)
inputs:
targetType: 'inline'
script: |
[string] $buildName = "$(Build.SourceBranchName)_$(versionNumber)"
Write-Host "Setting the name of the build to '$buildName'."
Write-Host "##vso[build.updatebuildnumber]$buildName"
- task: DotNetCoreCLI#2
displayName: "dotnet pack"
inputs:
command: 'pack'
packagesToPack: 'MyProj.csproj'
nobuild: true
versioningScheme: 'byEnvVar'
versionEnvVar: 'versionNumber'
packDestination: '$(Build.ArtifactStagingDirectory)'
- task: NuGetCommand#2
inputs:
command: 'push'
packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
nuGetFeedType: 'internal'
publishVstsFeed: 'XXXXXXXXX/YYYYYYYYYYYY'
allowPackageConflicts: true
To publish to an Azure Artifacts feed, set the Project Collection Build Service identity to be a Contributor on the feed. And add the following snippet to your azure-pipelines.yml file.
steps:
- task: NuGetAuthenticate#0
displayName: 'NuGet Authenticate'
- task: NuGetCommand#2
displayName: 'NuGet push'
inputs:
command: push
publishVstsFeed: '<projectName>/<feed>'
allowPackageConflicts: true
Refer to the documentation here:
https://learn.microsoft.com/en-us/azure/devops/pipelines/artifacts/nuget?view=azure-devops&tabs=yaml

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)

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

Grab libraries from another project and reference them in a new one via YAML in build pipeline

Trying to use library from another project in Azure build pipeline. My project depends on that reference.
pool:
name: Hosted Ubuntu 1604
steps:
- task: DownloadBuildArtifacts#0
displayName: 'Download Build Artifacts'
inputs:
buildType: specific
project: '8d7f1dea-4875-48da-9521-1761f7925dec'
pipeline: 4
artifactName: drop
itemPattern: |
drop/CSC.Automation/CSC.Automation.dll
drop/CSC.Automation/CSC.dll
- task: DotNetCoreCLI#2
displayName: Restore
inputs:
command: restore
projects: '$(Parameters.RestoreBuildProjects)'
- task: DotNetCoreCLI#2
displayName: Build
inputs:
projects: '$(Parameters.RestoreBuildProjects)'
arguments: '--configuration $(BuildConfiguration)'
- task: DotNetCoreCLI#2
displayName: Test
inputs:
command: test
projects: '$(Parameters.TestProjects)'
arguments: '--configuration $(BuildConfiguration)'
enabled: false
- task: DotNetCoreCLI#2
displayName: Publish
inputs:
command: publish
publishWebProjects: True
arguments: '--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)'
zipAfterPublish: false
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
condition: succeededOrFailed()
the above YAML code shows me grabbing an artifact and the exact two libraries i need in the current project. Since the current project is missing those libraries I need it to reference them. Anythoughts?