Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable Substitution for file with array type in azure pipeline file transform

In the config file ( json ) of my program, there is a field whose value type is a list of objects. My question is, how can I edit it in the pipeline?

In the following case I want to change "DownstreamScheme" from "https" to "http".

How should I define the variable so that the program can do this?

{
  "Routes": [
    {
      "DownstreamPathTemplate": "/{everything}",
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 44354
        }
      ],
      "UpstreamPathTemplate": "/authentication/{everything}",
      "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete" ]

      //,
      //"AuthenticationOptions": {
      //  "AuthenticationProviderKey": "Bearer",
      //  "AllowedScopes": []
      //}
      //,"RateLimitOptions": {
      //  "ClientWhitelist": [],
      //  "EnableRateLimiting": true,
      //  "Period": "5s",
      //  "PeriodTimespan": 1,
      //  "Limit": 1
      //}
    },
    {
      "DownstreamPathTemplate": "/{everything}",
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 44333
        }
      ],
      "UpstreamPathTemplate": "/company/{everything}",
      "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete" ]
    },
    {
      "DownstreamPathTemplate": "/{everything}",
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 44372
        }
      ],
      "UpstreamPathTemplate": "/navigator/{everything}",
      "UpstreamHttpMethod": [ "Get", "Post", "Put", "Delete" ]
    }


  ],


  "GlobalConfiguration": {
    "BaseUrl": "http://localhost:44395"

  }
}
like image 615
mohammad ghari Avatar asked Jan 23 '26 23:01

mohammad ghari


1 Answers

How should I define the variable so that the program can do this?

You can define the Pipeline variable: Routes.0.DownstreamScheme : http

For example:

enter image description here

Then you can use File Transform task to update the value to http.

steps:
- task: FileTransform@1
  displayName: 'File Transform: '
  inputs:
    folderPath: '$(build.sourcesdirectory)'
    fileType: json
    targetFiles: appsettings.json
like image 169
Kevin Lu-MSFT Avatar answered Jan 27 '26 00:01

Kevin Lu-MSFT