bryanbcook
bryanbcook

Reputation: 18328

tfx-cli: Unable to set version and overrides-file when packaging vss-extension

I'm following the guidance for building vss-extensions where I split my vss-extension.json into two parts:

Currently, my multi-stage YAML pipeline has a Build stage where I generate both the dev and production versions of the extension, and then I have separate Dev and Prod stages where I publish the extension to the marketplace.

The Build stage uses the Azure DevOps Extensions Tasks to query the existing version number in the marketplace, then package the extensions with the new version. I'd like to have the dev and prod versions of the extension to stay in sync and have the same version numbers, even if not all release-candidates aren't deployed to prod. In other words, dev might have versions 1.0.0, 1.0.1, 1.0.2, 1.0.3, but the production environment might only have 1.0.0 and 1.0.3. Both 1.0.3 versions would be based off the same commit.

My build stage looks something like:

- stage:
  jobs:
  - steps:

    - ... steps to build

    # this populates $(Query.Extension.Version) with the correct version number
    - task: QueryAzureDevOpsExtensionVersion@5
      name: Query
      inputs:
        connectTo: 'VsTeam'
        connectedServiceName: 'AzureDevOpsMarketPlace'
        publisherId: $(publisherId)
        extensionId: $(extensionId)-dev
        versionAction: 'Patch'

    # package for dev
    - task: PackageAzureDevOpsExtension@5
      inputs:
        rootFolder: $(Build.SourcesDirectory)
        extensionVersion: $(Query.Extension.Version)
        updateTasksVersion: true
        updateTasksVersionType: patch
        extensionVisibility: private
        arguments: --overrides-file vss-extension.dev.json
        outputPath: $(Build.ArtifactStagingDirectory)/dev
        
     # package for prod
    - task: PackageAzureDevOpsExtension@5
      inputs:
        rootFolder: $(Build.SourcesDirectory)
        extensionVersion: $(Query.Extension.Version)
        updateTasksVersion: true
        updateTasksVersionType: patch
        extensionVisibility: private
        outputPath: $(Build.ArtifactStagingDirectory)/prod

The prod package is fine. However, when I package dev package the PackageAzureDevOpsExtension@5 task takes the extensionVersion and writes it to a temporary file and then specifies this in the --overrides-file command-line argument. Since I'm also specifying the --overrides-file vss-extension.dev.json in the arguments parameter, the --overrides-file command-line argument is emitted twice.

# line-breaks for readability...
/opt/hostedtoolcache/tfx/0.18.0/x64/bin/tfx extension create --json --no-color 
    --root /home/vsts/work/1/s 
    --manifest-globs vss-extension.json 
    --loc-root /home/vsts/work/1/s 
    --overrides-file /home/vsts/work/_temp/PackageTask-1973-gfd71ZpqVY3S-.tmp 
    --overrides-file vss-extension.dev.json 
    --output-path /home/vsts/work/1/a/dev

It seems like if multiple --overrides-file arguments are specified only the last one is respected because the version number is not appearing in the output.

Is there another way on the command-line to set both the --overrides-file and the version?

Upvotes: 0

Views: 58

Answers (1)

bryanbcook
bryanbcook

Reputation: 18328

I discovered that I can pass both --overrides-file <file> and --override <json> in the arguments:

- task: PackageAzureDevOpsExtension@5
  displayName: Package Extension (DEV)
  inputs:
    rootFolder: '$(Build.SourcesDirectory)'
    #extensionVersion: '$(Query.Extension.Version)'
    updateTasksVersion: true
    updateTasksVersionType: 'patch'
    extensionVisibility: 'private' 
    arguments: >
       --overrides-file vss-extension.dev.json 
       --override "{'version':'$(Query.Extension.Version)'}"
    outputPath: $(Build.ArtifactStagingDirectory)/dev

While the --override setting worked well for me locally, I couldn't get the raw JSON to be accepted on the linux build agent.

I ended up modifying the vss-extension.dev.json to include the version attribute:

- pwsh: |
    $override = Get-Content $env:file -Raw | ConvertFrom-Json
    $override | Add-Member "version" -Value $env:version -Type NoteProperty
    $override | ConvertTo-Json | Set-Content $env:file -Force
  env:
    version: $(Query.Extension.Version)
    file: vss-extension.dev.json
  displayName: 'Modify dev package settings'

- task: PackageAzureDevOpsExtension@5
  displayName: Package Extension (DEV)
  inputs:
    rootFolder: '$(Build.SourcesDirectory)'
    #extensionVersion: '$(Query.Extension.Version)'
    updateTasksVersion: true
    updateTasksVersionType: 'patch'
    extensionVisibility: 'private' 
    arguments: --overrides-file vss-extension.dev.json 
    outputPath: $(Build.ArtifactStagingDirectory)/dev

Upvotes: 0

Related Questions