Nuget package not available in artifact - azure-devops

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

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

Azure DevOps CI/CD pipeline No package found error

I have a Azure DevOps CI/CD pipeline:
trigger:
- master
pool:
vmImage: ubuntu-latest
variables:
buildConfiguration: 'Release'
stages:
- stage: Build
jobs:
- job: Build
displayName: 'Build'
steps:
- task: DotNetCoreCLI#2
inputs:
command: 'build'
configuration: 'Release'
projects: |
$(System.DefaultWorkingDirectory)/src/*.csproj
arguments: --output $(System.DefaultWorkingDirectory)/publish_output --configuration $(buildConfiguration)
- task: ArchiveFiles#2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)/publish_output'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
- publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
artifact: drop
- stage: Test
dependsOn: Build
condition: succeeded()
jobs:
- job: Deploy
displayName: 'Deploy to Test'
steps:
- task: AzureRmWebAppDeployment#4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'xxx'
appType: 'webApp'
WebAppName: 'xxx'
package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
When I run it I get
Error: No package found with specified pattern: /home/vsts/work/1/drop/13325.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.
The build stage produces an artifact, and it is in the 'drop' directory, so I can not wrap my mind around it why publish task can not find it?
As #Daniel indicated you will also need a download artifacts task inside your Test stage as the different stages keep separate working directories.
- stage: Test
dependsOn: Build
condition: succeeded()
jobs:
- job: Deploy
displayName: 'Deploy to Test'
steps:
- task: DownloadBuildArtifacts#1
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'drop'
downloadPath: '$(System.ArtifactsDirectory)'
- task: AzureRmWebAppDeployment#4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'xxx'
appType: 'webApp'
WebAppName: 'xxx'
package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'

TypeError: stats.jsonToString is not a function Azure DevOps Pipeline

I am making a pipeline on VSTS, added webpack into my yaml file and it is erroring on that task:
##[error]TypeError: stats.jsonToString is not a function. Is there any way setup a webpack 5 in azure vsts?
My package.json:
"scripts": {
"start": "webpack serve --config ./webpack.config.js --mode development",
"build": "webpack --mode production",
"production": "webpack --progress --json --mode production --config webpack.config.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
My Pipeline looks like this:
trigger:
- master
pool:
name: 'Hosted VS2017'
vmImage: 'windows-latest'
demands:
- msbuild
- visualstudio
- npm
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
displayName: 'NuGet restore'
inputs:
restoreSolution: '$(Solution)'
- task: Npm#1
inputs:
command: 'install'
workingDir: ''
- task: webpack#4
displayName: webpack
inputs:
webpackCliArguments: '--config webpack.config.js'
treatErrorsAs: 'errors'
treatWarningsAs: 'warnings'
workingFolder: ''
- task: DotNetCoreCLI#2
displayName: 'dotnet restore'
inputs:
command: restore
projects: '**/*.csproj'
- task: DotNetCoreCLI#2
displayName: 'dotnet build'
inputs:
command: 'build'
- task: DotNetCoreCLI#2
displayName: 'dotnet publish'
inputs:
command: 'publish'
- task: PublishSymbols#1
displayName: 'Publish symbols path'
inputs:
SearchPattern: '**\bin\**\*.pdb'
continueOnError: true
- task: CopyFiles#2
inputs:
targetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact'
inputs:
PathtoPublish: '$(Build.artifactstagingdirectory)'
ArtifactName: 'Drop'
As the similar issue you shared, there are two workarounds:
Add a Yarn task with the same command and args as local.
Use a CMD task with follwoing command.
node ".\node_modules\webpack\bin\webpack.js" --json --mode production --output-path "$(Build.BinariesDirectory)\dist"
When it doesn't recognise node command, please install with Node.js Tool task.
steps:
- task: NodeTool#0
inputs:
versionSpec: 13.x
- task: Bash#3
inputs:
targetType: 'inline'
script: 'node --version'

Azure DevOps Pipeline not update correct the website

i build a pipeline, that should run on changes on master-branch. at the moment, it runs right, but the code is not changed. If i delete and recreate the pipeline, the update is correct installed. Where is my Error? The server is actually a F1 Plan from Azure (a linux maschine).
parameters:
- name: artifactName
type: string
default: drop
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
displayName: 'Use NuGet 5.11.0'
inputs:
versionSpec: 5.11.0
checkLatest: true
- task: NuGetCommand#2
displayName: 'NuGet restore'
inputs:
restoreSolution: '$(Parameters.solution)'
- task: DotNetCoreCLI#2
displayName: 'dotnet publish'
inputs:
command: publish
publishWebProjects: false
projects: '**/*.csproj'
arguments: '-r linux-x64 --output $(build.artifactstagingdirectory)'
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
ArtifactName: '$(Parameters.ArtifactName)'
condition: succeededOrFailed()
- task: AzureRmWebAppDeployment#4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: '...nameOfSubscription'
appType: 'webAppLinux'
WebAppName: '...nameOfWebApp'
packageForLinux: '$(build.artifactstagingdirectory)/*.zip'
RuntimeStack: 'DOTNETCORE|5.0'
You simply didn't deploy application to Azure. What you did is create a package for deployment.
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
ArtifactName: '$(Parameters.ArtifactName)'
condition: succeededOrFailed()
It publishes artifact, but it doesn't publish your app to Azure.
Please take a look on documentation here
If you want to do this in the same job it would be like:
- task: AzureWebApp#1
inputs:
azureSubscription: '<Azure service connection>'
appType: 'webAppLinux'
appName: '<Name of web app>'
package: '$(build.artifactstagingdirectory)/*.zip'
Please remeber to provide all needed details.

Nuget package Version Issue for YAML

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.