我正在开发 YAML 管道,它只是基于保存在我的 Azure DevOps 存储库中的 main.bicep 文件(目前仅通过它部署 azure ADF)来部署 HUB 资源。但是,我需要访问二头肌部署的“输出” - 例如,我需要一些已部署的 Azure 资源的 ID。 (部署也没有问题>>最后我确实部署了 ADF)
这是代码: 阶段:
# DEPLOYING INFRASTRUCTURE - HUB
- stage: DeployHub
displayName: Deploy Hub Infrastructure
jobs:
- deployment: DeployHub
displayName: Deploy Hub Infrastructure
environment: '$(testEnvironment)' #used for the manual approval conditions
strategy:
runOnce:
deploy:
steps:
# the checkout will enable the use of "git diff" as to see which files have been modified in the latest commit at some point
- checkout: git://${{ variables.my_org }}/my_project@refs/heads/feature_branch_01
# Actual deployment of the resources - HUB
- task: AzureResourceManagerTemplateDeployment@3
name: ARM_Template_Deployment_HUB
displayName: 'Bicep Deployment Task HUB'
inputs:
deploymentScope: 'Resource Group'
azureResourceManagerConnection: '$(serviceConnection)'
action: 'Create Or Update Resource Group'
resourceGroupName: '$(rgTesting)'
location: 'some_location'
templateLocation: 'Linked artifact'
csmFile: '$(Build.SourcesDirectory)/$(bicepFilePathHUB_Test)'
deploymentMode: Incremental
deploymentOutputs: 'armOutputsHUB'
所以问题是:
我尝试过但没有成功:
- task: PowerShell@2
displayName: 'Parse ARM deploymentOutputs'
env:
ARM_OUTPUTS: $(armOutputsHUB)
inputs:
targetType: 'inline'
errorActionPreference: continue
workingDirectory: '$(Pipeline.Workspace)' #default is "$(Build.SourcesDirectory)"
pwsh: true
script: |
Write-Host "armOutputsHUB = $armOutputsHUB" # >>nothing inside
Write-Host "armOutputsHUB = $($armOutputsHUB)" # >> nothing inside
Write-Host "armOutputsHUB = $($ARM_Template_Deployment_HUB.armOutputsHUB)" # >> nothing inside
$outputsObject = $env:ARM_OUTPUTS | ConvertFrom-Json
# error: Conversion from JSON failed with error: Unexpected character encountered while parsing value: $. Path '', line 0, position 0.
Write-Host "outputsObject = $($outputsObject)" # >>nothing inside
Write-Host "outputsObject = $outputsObject" # >>nothing insi
任何供我测试的想法或解决方案/代码将不胜感激!!
我在 GitHub 上为您找到了一个很好的示例管道。 它与您的一些示例非常相似,但您可能缺少字符串引号的使用......🚀
- task: PowerShell@2
name: 'SetDeploymentOutputVariables'
displayName: 'Set Deployment Output Variables'
inputs:
targetType: inline
script: |
$armOutputObj = '$(deploymentOutputs)' | ConvertFrom-Json
$armOutputObj.PSObject.Properties | ForEach-Object {
$keyname = $_.Name
$value = $_.Value.value
# Creates a standard pipeline variable
Write-Output "##vso[task.setvariable variable=$keyName;issecret=true]$value"
# Display keys in pipeline
Write-Output "output variable: $keyName"
}
pwsh: true
默认情况下,每个输出都由 JSON.stringify() 处理。 AzureResourceManagerTemplateDeployment@3 任务允许通过参数
useWithoutJSON: true
禁用此处理,在 UI 中称为“使用不应用 JSON.Stringify 的单独输出值”。