azure-devopsazure-pipelinesazure-artifacts

Azure DevOps yaml pipeline: configure Azure Artifacts "package" resource


Scenario:

Approach:

      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)

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?


Solution

  • 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/parameters.