3

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"

  }
}

1 Answer 1

6

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
Sign up to request clarification or add additional context in comments.

1 Comment

Will it update the value of each DownstreamScheme ? Or just the 0th (first) reference ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.