From reading the Azure DevOps documentation here, it looks like it's possible to define variables in scripts, but only for Bash and Powershell tasks. If I want to use the Azure Powershell task, it does not seem to work. Here is my yaml for what I am trying to do.
- stage: promote_image
displayName: Promote VM Image to Prod
jobs:
- job: VMPush
steps:
- task: AzurePowerShell@5
inputs:
ScriptType: 'InlineScript'
Inline: |
$srcimageversion = get-azgalleryimageversion -ResourceGroupName $srcRG `
-GalleryName $srcgallery `
-GalleryImageDefinitionName $srcimagename | select -last 1
Write-Host "##vso[task.setvariable variable=VersionName;isOutput=true]$srcimageversion.Name"
Write-Host "##vso[task.setvariable variable=SourceId;isOutput=true]$srcimageversion.Id.ToString()"
Write-Host "Version name is $($env:VersionName)"
Write-Host "VM source is $($env:SourceId)"
azurePowerShellVersion: 'LatestVersion'
azureSubscription: $(nonProd_Subscription)
- task: AzurePowerShell@5
inputs:
ScriptType: 'InlineScript'
Inline: |
Write-Host "Version name is $($env:VersionName)"
Write-Host "VM source is $($env:SourceId)"
azurePowerShellVersion: 'LatestVersion'
azureSubscription: $(prod_Subscription)
The VersionName and SourceId variables don't get output in either task. Is it even possible to set variables like this with the Azure Powershell task? I am using the Azure Powershell task since I need to obtain information from a resource in one Azure subscription and then use it to deploy something in another Azure subscription.