Search code examples
azureazure-devopsazure-pipelinescicdazure-bicep

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


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"
    }
  }
}

Solution

  • The solution is to change

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

    to

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