What steps can I take to fix an InvalidRequestContent error when substituting variables with FileTransform@1 in Azure Pipelines?

huangapple go评论94阅读模式
英文:

What steps can I take to fix an InvalidRequestContent error when substituting variables with FileTransform@1 in Azure Pipelines?

问题

FileTransform@1失败于变量替换

我正尝试用我的变量组中的变量值替换main.parameters.json文件中的值。

文件转换显示绿色勾选,并表示该值已被替换,但what-if显示错误。

这是错误信息:

> 错误:{"error":{"code":"InvalidRequestContent","message":"请求内容无效,无法反序列化:'将值\"test\"转换为类型\"Azure.Deployments.Core.Definitions.DeploymentParameterDefinition\"的错误。路径\"properties.parameters.tier\",第1行,第81个位置。"}}

> ##[error]脚本以退出代码1失败。

这是我的yaml代码的一部分:

`trigger:
  batch: true
  branches:
    include:
    - master
  paths:
    include:
    - bicep
 
pool:
  vmImage: windows-latest

variables:
  - group: myGroup
  - name: parameters.tier
    value: "$(tier)"

stages:

- stage: Preview
  jobs:
  - job: PreviewAzureChanges
    displayName: Preview Azure changes
    steps:
    - task: PowerShell@2
      inputs:
        targetType: 'inline'
        script: |
          echo "Print tier value"
          echo "Value: $(tier)"          

    - task: FileTransform@1
      displayName: 'File transformation: main.parameters.json'
      inputs:
        folderPath: 'bicep\'
        targetFiles: 'main.parameters.json'
        fileType: json

    - task: AzureCLI@2
      name: RunWhatIf
      displayName: Run what-if
      inputs:
        azureSubscription: $(environment)
        scriptType: bash
        scriptLocation: inlineScript
        inlineScript: |
          az deployment group what-if \
            --resource-group $(rg) \
            --template-file 'bicep\main.bicep' \
            --parameters 'bicep\main.parameters.json'`          

这是我的main.parameters.json:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "franchisee": {
      "value": "myFranchisee"
    },
    "tier": {
      "value": "myTier"
    },
    "location": {
      "value": "myLocation"
    },
    "rg": {
      "value": "myRg"
    }
  }
}
英文:

FileTransform@1 fails for variable substitution

I'm trying to substitute the values in the main.parameters.json file to the variable values from my variable group.

The file transform gives a green check and says that the value has been substituted, however the what-if gives an error.

This is the error:

> ERROR: {"error":{"code":"InvalidRequestContent","message":"The request content was invalid and could not be deserialized: 'Error converting value "test" to type 'Azure.Deployments.Core.Definitions.DeploymentParameterDefinition'. Path 'properties.parameters.tier', line 1, position 81.'."}}
> ##[error]Script failed with exit code: 1

This is the part of my yaml code:

`trigger:
  batch: true
  branches:
    include:
    - master
  paths:
    include:
    - bicep
 
pool:
  vmImage: windows-latest

variables:
  - group: myGroup
  - name: parameters.tier
    value: "$(tier)"

stages:

- stage: Preview
  jobs:
  - job: PreviewAzureChanges
    displayName: Preview Azure changes
    steps:
    - task: PowerShell@2
      inputs:
        targetType: 'inline'
        script: |
          echo "Print tier value"
          echo "Value: $(tier)"

    - task: FileTransform@1
      displayName: 'File transformation: main.parameters.json'
      inputs:
        folderPath: 'bicep\'
        targetFiles: 'main.parameters.json'
        fileType: json

    - task: AzureCLI@2
      name: RunWhatIf
      displayName: Run what-if
      inputs:
        azureSubscription: $(environment)
        scriptType: bash
        scriptLocation: inlineScript
        inlineScript: |
          az deployment group what-if \
            --resource-group $(rg) \
            --template-file 'bicep\main.bicep' \
            --parameters 'bicep\main.parameters.json'`

This is my main.parameters.json:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "franchisee": {
      "value": "myFranchisee"
    },
    "tier": {
      "value": "myTier"
    },
    "location": {
      "value": "myLocation"
    },
    "rg": {
      "value": "myRg"
    }
  }
}

答案1

得分: 2

将以下内容进行翻译:

从:

variables:

  • group: myGroup
  • name: parameters.tier
    value: "$(tier)"

到:

variables:

  • group: myGroup
  • name: parameters.tier.value
    value: "$(tier)"
英文:

The solution is to change

variables:
  - group: myGroup
  - name: parameters.tier
    value: "$(tier)"

to

variables:
  - group: myGroup
  - name: parameters.tier.value
    value: "$(tier)"

huangapple
  • 本文由 发表于 2023年5月22日 19:54:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/76305907.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定