UPDATE
I've just released a verion of the Azure DevOps Extension Tasks that can set the flag on the output variable (version 3.1.123), I'll make this the default in v4, since it's a breaking change.
steps:
- task: QueryAzureDevOpsExtensionVersion@3
  displayName: 'Query Extension Version: jessehouwing.jessehouwing-vsts-variable-tasks'
  name: Query
  inputs:
    connectedServiceName: Marketplace
    publisherId: jessehouwing
    extensionId: 'jessehouwing-vsts-variable-tasks'
    versionAction: Patch
    setOutputFlag: true
Version 4 removed the need to set anything and always registers an output variable:
steps:
- task: QueryAzureDevOpsExtensionVersion@4
  displayName: 'Query Extension Version: jessehouwing.jessehouwing-vsts-variable-tasks'
  name: Query
  inputs:
    connectedServiceName: Marketplace
    publisherId: jessehouwing
    extensionId: 'jessehouwing-vsts-variable-tasks'
    versionAction: Patch
You can then reference the variable using Query.Extension.Version in the same job or with: dependencies.JobA.outputs['Query.Extension.Version'] across jobs.
Before
You can try my Variables Tasks:
- task: VariableSetTask@2
  name: SetVersion
  displayName: 'Set variable: TaskExtensionVersion to: ''$(Task.Extension.Version)'''
  inputs:
    variableName: TaskExtensionVersion
    Value: '$(Task.Extension.Version)'
    IsOutput: true
Or use a Powershell script:
- powershell: |
   $value = $env:version
   Write-Host "##vso[task.setvariable variable=TaskExtensionVersion;isoutput=true]$value"
  displayName: 'PowerShell Script'
  name: SetVersion
  env:
    version: $(Task.Extension.Version)
I don't think the extension tasks currently register the variable as an output variable across stages.
Then make sure you reference the variable using the correct syntax:
$(dependencies.JobA.outputs['SetVersion.TaskExtensionVersion'])
Be sure to add the name: parameter to your Job and your Task so the output variable can be referenced. The naming of tasks and jobs and declaring dependencies is required to make this work. See the docs on this topic: