1
votes

Scenario:

  • configure an Azure DevOps yaml deployment pipeline for a front-end app
  • the front-end resources are published to Azure Artifacts as an NPM package
  • Azure DevOps pipeline promotes initial package to a number of stages

Approach:

  • Alt. 1: explicit "Download Package" task to download npm package from Azure Artifacts feed
      displayName: "Artifacts - download"
      inputs:
        packageType: 'npm'
        feed: '38a52be4-9352-453e-af97-5c3b448652f0/38a52be4-9352-453e-af97-5c3b448652f0'
        view: '070e33c7-f5c8-4561-8186-5c3b448652f0'
        definition: '1f32cfbf-1427-4b27-8476-5c3b448652f0'
        version: '1.0.1'
        downloadPath: '$(System.ArtifactsDirectory)'

This sort of works, but it requires either to specify a hard-coded version inside the yaml-definition or else a wildcard "*" (latest version). Ideally, the version could be specified at runtime via the "Run Pipeline"-dialog. However, this requires for the package to be configured as a resource (Alt. 2)

  • Alt. 2: specify a "package" resource on top of the yaml-definition.

According to the docs, there are number of possible resources: pipelines, builds, repositories, containers, packages and webhooks. In this case, "packages" resource seems approriate.

resources:
  packages:
    - package: contoso
      type: npm
      connection: pat-contoso
      name: yourname/contoso 
      version: 7.130.88 
      trigger: true

However, the docs are lacking, only providing one example for GitHub packages.

I can't find any example, specifically for an "Azure Artifacts" package.

Who can share a working "package"-configuration, specifically for Azure Artifacts?

2

2 Answers

1
votes

You can use runtime parameters with your first option

parameters:
- name: packageVersion
  displayName: Package version
  type: string
  default: '1.0.1'

trigger: none

jobs:
- job: Deploy
  displayName: Deploy
  steps:
  - task: DownloadPackage@1
    displayName: "Artifacts - download"
    inputs:
        packageType: 'npm'
        feed: '38a52be4-9352-453e-af97-5c3b448652f0/38a52be4-9352-453e-af97-5c3b448652f0'
        view: '070e33c7-f5c8-4561-8186-5c3b448652f0'
        definition: '1f32cfbf-1427-4b27-8476-5c3b448652f0'
        version: '${{ parameters.packageVersion }}'
        downloadPath: '$(System.ArtifactsDirectory)'

And I'm afraid that you won't be able to combine this with resource as it can't support any way of templates/variables/paramataers.

1
votes

As Krzysztof suggests, the Runtime parameters should work for the version could be specified at runtime via the Run Pipeline -dialog. And you may need to add extract: false if you want to download the package archive.

I can't find any example, specifically for an "Azure Artifacts" package.

For now it's not supported for Azure Artifact Npm package, this document has stated that Resources: packages option is only for Nuget/Npm github packages.