我正在使用我的天蓝色管道中的一系列标签,从
yml
文件到 template
tags:
environment: 'Development'
owner: 'owername'
chargeCode: 'x001'
product: 'productname'
supportteam: 'supportTeamName'
在将其接收到我的模板中时,我将其作为对象获取,例如:
parameters:
- name: tags
type: object
default: {}
另外,我正在尝试使用
powershell
任务修复 json 字符串:
- powershell: |
$mayarrstr= @"
${{ convertToJson(parameters.tags) }}
"@
Write-Host $mayarrstr
$mayarrstr = $mayarrstr -replace '"', "'"
Write-Host $mayarrstr
$jsonObject = $mayarrstr | ConvertFrom-Json
echo "##vso[task.setvariable variable=tags]$jsonObject"
displayName: 'Set Tags Variable'
但目前要将其接收到我的二头肌文件中。我正在使用:
param tags object = {}
但是每次收到都说字符串无法解析为json,或者字符错误
[0] ={
如果我必须使用
tags
将字符串解析为 AzureCLI@2
,如何将 object
设置为我的资源?
您可以尝试将 JSON 字符串作为参数传递给 bicep 文件:
param tags object = json(tagJsonObj)
parameters:
- name: tags
type: object
default:
environment: Development
owner: owername
chargeCode: x001
product: productname
supportteam: supportTeamName
. . .
steps:
- task: PowerShell@2
displayName: 'Set tags json object'
inputs:
targetType: inline
script: |
$tagsJsonStr = @"
${{ convertToJson(parameters.tags) }}
"@
Write-Host $tagsJsonStr
$tagsJsonStr = $tagsJsonStr.Replace('"', '\"').Replace("`r", "").Replace("`n", "")
Write-Host $tagsJsonStr
Write-Host "##vso[task.setvariable variable=tags;]$tagsJsonStr"
- task: AzureCLI@2
displayName: 'Bicep deployment'
inputs:
azureSubscription: MyArmConnection
scriptType: pscore
scriptLocation: inlineScript
inlineScript: 'az deployment group create --resource-group {resource-group} --template-file {path-to-bicep} --parameters tagJsonObj=''$(tags)'''