BendEg
BendEg

Reputation: 21088

Publish nuget package in azure devops from build or release pipeline

Where is the correct place to publish nuget packages in azure devops? Is it better to use the build or release pipeline?

One solution would be to just create an artifact (zip) in build and download it in release an create a nuget packge.

EDIT

Solved it with conditional tasks:

trigger:
  branches:
    include:
    - master
    - dev
  paths:
    include:
    - src/*
    - test/*
    - azure-pipelines.yml

pr:
  branches:
    include:
    - '*'

pool:
  vmImage: 'ubuntu-16.04'

variables:
  buildConfiguration: 'Release'

steps:
- task: UseDotNet@2
  displayName: 'Use dotnet sdk 3.x'
  inputs:
    version: 3.x
    includePreviewVersions: false

- task: DotNetCoreCLI@2
  displayName: Restore
  inputs:
    command: restore
    projects: '**/*.csproj'

- task: DotNetCoreCLI@2
  condition: eq(variables['Build.SourceBranch'], 'refs/heads/master')
  displayName: Build_release
  inputs:
    command: build
    projects: '**/*.csproj'
    arguments: '--configuration release'

- task: DotNetCoreCLI@2
  condition: ne(variables['Build.SourceBranch'], 'refs/heads/master')
  displayName: Build_Debug
  inputs:
    command: build
    projects: '**/*.csproj'
    arguments: '--configuration debug'

- task: DotNetCoreCLI@2
  displayName: Test
  inputs:
    command: test
    projects: '**/*Test/*.csproj'
    arguments: '--configuration $(buildConfiguration)'

- task: NuGetToolInstaller@1
  displayName: 'Install nuget 5.x'
  inputs:
    versionSpec: '5.x'

- task: NuGetCommand@2
  displayName: 'Pack nuget'
  inputs:
    command: 'pack'
    packagesToPack: 'src/**/*.csproj'
    packDestination: '$(Build.ArtifactStagingDirectory)'

- task: NuGetCommand@2
  condition: eq(variables['Build.SourceBranch'], 'refs/heads/master')
  displayName: 'Push to nuget feed sample-cloud'
  inputs:
    command: 'push'
    packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
    nuGetFeedType: 'internal'
    publishVstsFeed: '<guid>'
    allowPackageConflicts: true

- task: NuGetCommand@2
  condition: eq(variables['Build.SourceBranch'], 'refs/heads/dev')
  displayName: 'Push to nuget feed sample-cloud-dev'
  inputs:
    command: 'push'
    packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
    nuGetFeedType: 'internal'
    publishVstsFeed: '<guid>/<guid>'

Upvotes: 2

Views: 2077

Answers (1)

Leo Liu
Leo Liu

Reputation: 76760

Publish nuget package in azure devops from build or release pipeline

This is definitely your personal preference, it is a matter of taste, and there is no standard requirement or process.

Generally speaking, the process of publishing the package is: build the project/solution->Pack the .csproj/.nuspec file to generate the nuget package->publish the generated package, we do not deliberately split the build and release process into CI and CD, so that we do not need additional pipeline overhead do not need to pass artifacts between the build and release pipeline.

So, we could generate the package and publish the package in the build pipeline by the NuGet task pack and push.

Of course, if the package release and CI, CD have strict standard requirements, we need to publish the package in the release pipeline. For example, In the build pipeline, we generate the pre-release package, but if we are required to only publish the stable versions package, in this case, we need to create a release pipeline to publish the stable package, otherwise, we have to manually enable/disable the push task in the build pipeline.

Hope this helps.

Upvotes: 4

Related Questions