1
votes

I have a build configuration defined here:

https://github.com/cpoDesign/APIFramework/blob/master/azure-pipelines.yml

I have managed to generate a nuget package using the following command

- task: DotNetCoreCLI@2
  inputs:
    command: pack
    projects: '**/*ApiFramework.csproj'

A subset of the task output of the script is

  Task "PackTask"
2018-11-27T23:02:32.4459067Z          Successfully created package '/home/vsts/work/1/a/CPODesign.ApiFramework.1.0.0.nupkg'.

Next step resolved:

I do not want to create a build with release into nuget as those steps have to be logically separated. Therefore I have created a new step Create a drop.

Configuration:

My drop task definition:

- task: PublishBuildArtifacts@1
  inputs:
    pathtoPublish: '$(Build.ArtifactStagingDirectory)'
    artifactName: drop
    contents: '**/$(BuildConfiguration)/**/?(*.nupkg)'

Build output:

2018-11-27T23:04:24.6351310Z ##[section]Starting: PublishBuildArtifacts
2018-11-27T23:04:24.6353582Z ==============================================================================
2018-11-27T23:04:24.6353896Z Task         : Publish Build Artifacts
2018-11-27T23:04:24.6353944Z Description  : Publish build artifacts to Azure Pipelines/TFS or a file share
2018-11-27T23:04:24.6354007Z Version      : 1.142.2
2018-11-27T23:04:24.6354046Z Author       : Microsoft Corporation
2018-11-27T23:04:24.6354091Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=708390)
2018-11-27T23:04:24.6354156Z ==============================================================================
2018-11-27T23:04:26.1357631Z ##[section]Async Command Start: Upload Artifact
2018-11-27T23:04:26.1357755Z Uploading 1 files
2018-11-27T23:04:26.6373194Z File upload succeed.
2018-11-27T23:04:26.6373313Z Upload '/home/vsts/work/1/a' to file container: '#/1558454/drop'
2018-11-27T23:04:27.9231805Z Associated artifact 91 with build 806
2018-11-27T23:04:27.9231947Z ##[section]Async Command End: Upload Artifact
2018-11-27T23:04:27.9232436Z ##[section]Finishing: PublishBuildArtifacts

Note: The UI for azure-devops has changed and the artefacts (artifacts) are no longer created as a new tab but rather badly added into the report summary

The question:

How do I generate a specific version of nuget package IE: 1.0.%(Build.BuildId)?

My last attempt is

- task: DotNetCoreCLI@2
  inputs:
    command: pack
    projects: '**/*ApiFramework.csproj'
   # packageVersion:'1.0.$(Build.BuildId)'

where

   packageVersion:'1.0.$(Build.BuildId)'

Will cause the build to fail (the current branch is published here:https://github.com/cpoDesign/APIFramework/blob/cpoDesign-build-mods-1/azure-pipelines.yml)

2
If I understand correctly, you're question could be a case for looking into GitVersion. Using the GitVersion task from you build you'll be able to version your assemblies and packages in a semi-automated fashion. Have a look at their docs and repo - Herman Cordes

2 Answers

2
votes

after frustrating couple hours I have found the answer

  1. Publish the generated nuget package into build artefacts
  2. Generate a release to publish the nuget package

Build configuration

pool:
  vmImage: 'Ubuntu 16.04'

variables:
  buildConfiguration: 'Release'

steps:
- script: dotnet build --configuration $(buildConfiguration)
  displayName: 'dotnet build $(buildConfiguration)'

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

- script: dotnet test **/*.Tests.Unit.csproj --logger trx
- task: PublishTestResults@2
  inputs:
    testRunner: VSTest
    testResultsFiles: '**/*.trx'

- script: dotnet pack /p:PackageVersion='1.0.$(Build.BuildId)' --configuration $(buildConfiguration)  -o $(Build.ArtifactStagingDirectory)

- task: PublishBuildArtifacts@1
  inputs:
    pathtoPublish: '$(Build.ArtifactStagingDirectory)'
    artifactName: drop
    contents: '**/$(BuildConfiguration)/**/?(*.nupkg)'

Release section

I have updated the release to trigger after each successful build

dotnet nuget push artefactName.APIFramework/drop/CPODesign.ApiFramework.1.0.$(Build.BuildId).nupkg -k $(myapiKey) -s https://api.nuget.org/v3/index.json
0
votes

I can't see the contents as a valid input in the YAML for PublishBuildArtifacts@1

Do you mean to do a copy task first before you do the publish task. Like shown in the publish documentation? https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/publish-build-artifacts?view=vsts