DEV Community

Jacob Korsgaard
Jacob Korsgaard

Posted on

Get Azure Pipelines UniversalPackages version

I was building an azure pipelines job and during it I uploaded a Universal Package using the UniversalPackages task.

I then had to contact a REST API with the package and version of the newly published Universal Package. To do that I need to get the version and package name out of the task.

That looks like this:

    - task: UniversalPackages@0
      displayName: Universal Publish
      inputs:
        command: publish
        publishDirectory: '$(System.DefaultWorkingDirectory)/dist'
        vstsFeedPublish: 'MyProject/MyFeed'
        vstsFeedPackagePublish: 'package.name'
        packagePublishDescription: 'My super package'
        versionOption: patch #increment the patch part of the semantic versioning
        publishedPackageVar: someVariableName
Enter fullscreen mode Exit fullscreen mode

After this task runs $(someVariableName) will hold a string like so "package.name 1.0.1", but that variable will not be available outside this current job.

To make it available for other jobs you need to move it to an output variable. I did that like this:

    - powershell: echo "##vso[task.setvariable variable=PackageNameAndVersion;isOutput=true]$(someVariableName)"
      name: PackagePublish
Enter fullscreen mode Exit fullscreen mode

Now the value is available in other jobs through PackagePublish.PackageNameAndVersion.

You can consume it in subsequent jobs by making sure those jobs depend on this job and then grabbing the variable from the output.

- job: 'RestAPICallingJob'
  dependsOn: 'BuildProductionStuff'
  pool: server
  variables:
    PackageNameAndVersion: $[ dependencies.BuildProductionStuff.outputs['PackagePublish.PackageNameAndVersion'] ]
Enter fullscreen mode Exit fullscreen mode

Now I can add a step to call a REST API using the package name and version of my universal package.

NOTE: I ended up not using Universal Packages, because you can only download Universal Packages from Azure using the AzureCLI. Instead, I created a NuGet package that contained just my loose files using a .nuspec file.

Top comments (0)