Azure DevOps Pipeline Json Variable Substitution - Ocelot.json

514 views Asked by At

I have the following file ocelot.json and I want to change the Host object of each route configured inside the file through a variable. I want to change the localhost to the correct hostname through a variable.

"Routes": [
    //ParĂ¡metricas
    {
      "UpstreamPathTemplate": "/api/ClasificacionEquipo",
      "UpstreamHttpMethod": [ "GET" ],
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 19007
        }
      ],
      "DownstreamPathTemplate": "/api/ClasificacionEquipo",
      "FileCacheOptions": {
        "TtlSeconds": 3600,
        "Region": "parametricas"
      }
    },
    {
      "UpstreamPathTemplate": "/api/ClasificacionEquipo/{id}",
      "UpstreamHttpMethod": [ "GET" ],
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 19007
        }
      ],
      "DownstreamPathTemplate": "/api/ClasificacionEquipo/{id}",
      "FileCacheOptions": {
        "TtlSeconds": 300,
        "Region": "parametricas"
      }
    }
]

I create the following variable but it doesn't take me the change: Routes.DownstreamHostAndPorts.Host.

I have also tried as follows: Routes.*.DownstreamHostAndPorts.0.Host

And it hasn't worked for me

1

There are 1 answers

0
Ricky Gummadi On

If you want to do file transformation of JSON files in ADO we have the FileTransform@1 task

 - task: FileTransform@1
      displayName: Transform Json File
      inputs:
        folderPath: '$(System.DefaultWorkingDirectory)/<path-to-your-file>'
        fileType: 'json'
        targetFiles: '<your-file-name>.json'

More info on this https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/file-transform?view=azure-devops