问题描述
通过阅读Azure DevOps文档here,看起来可以在脚本中定义变量,但仅适用于Bash和Powershell任务。如果我要使用Azure Powershell任务,它似乎无法正常工作。这是我要执行的操作。
- 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)
在任一任务中,VersionName和SourceId变量均未获得输出。甚至可以通过Azure Powershell任务设置像这样的变量吗?我正在使用Azure Powershell任务,因为我需要从一个Azure订阅中的资源获取信息,然后使用它在另一个Azure订阅中部署某些东西。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)