gpt4 book ai didi

azure - 如何从 Azure DevOps YAML 管道访问 AzureResourceManagerTemplateDeployment (@3) 任务中的 "deploymentOutputs"?

转载 作者:行者123 更新时间:2023-12-02 06:35:10 26 4
gpt4 key购买 nike

我正在开发 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'

所以问题是:

  1. 如何访问armOutputsHUB?
  2. 如果我在同一个作业、阶段中访问它,有什么关系吗?
  3. 它保存在哪里? - 我读到所有部署类型的作业都保存在:“部署作业使用 $(Pipeline.Workspace) 系统变量”。来源:https://learn.microsoft.com/en-us/azure/devops/pipelines/process/deployment-jobs?view=azure-devops但是,我仍然找不到名为“armOutputsHUB”的变量

我尝试过但没有成功:

  1. 在与下一个任务相同的工作中:
            - 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 上为您找到了一个很好的示例管道。它与您的一些示例非常相似,但您可能缺少字符串引号的使用。

The pipeline


- 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

关于azure - 如何从 Azure DevOps YAML 管道访问 AzureResourceManagerTemplateDeployment (@3) 任务中的 "deploymentOutputs"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76236059/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com