2
votes

I am quite new in Azure and i have a task to update a json file's values at deployment time. I have 3 deployment slots in Azure release pipeline Dev, Stage and Prod.

I have following Json file which need to update.

"tables": [{
    "name": "CustomerContract",
    "columns": [{
               "name": "Year",
               "dataType": "int64",
               "sourceColumn": "Year",
               "summarizeBy": "none"
           },
           {
               "name": "<devname>",
               "dataType": "int64",
               "sourceColumn": "CustomerNumber",
               "summarizeBy": "none",
               "isHidden": <trueifdev>
           }
    ],
    "partitions": [{
        "name": "Partition",
        "dataView": "full"
    }]
  },
}

In above json file i need to update following key's values.

  • "isHidden"
  • "name"

above two key's values are different based on slots (Dev, Stage & Prod).

Please help me out how can i change/update the values of above keys at deployment time based on slots?

Following link didn't worked in my case because my json files belongs to sharepoint data models.

Azure Dev ops replace tokens per environment in release pipeline

1
where is the json-File located? Is it part of your repository? You could use a custom task to solve that, depends where your json-File is located. I recommad powershell task for that. - Mar Tin
json file is located in my artifact. - Ashish-BeJovial
hm, I don't have any experiance how to access files inside the artifact. - Mar Tin
you can use token replace task, if your json file contains tokens, if not - you can use powershell script to replace values - 4c74356b41
It is working fine. I have accepted your answer. Thank you so much. I have one more issue considering same json file. If i want to change values based on values not keys, is it possible? - Ashish-BeJovial

1 Answers

2
votes

Please help me out how can i change/update the values of above keys at deployment time based on slots?

If the Json file is not generated during building. We still could use the task Replace Tokens to update the key's values.

As test, change the definition of the key's values:

"tables": [{
    "name": "CustomerContract",
    "columns": [{
               "name": "Year",
               "dataType": "int64",
               "sourceColumn": "Year",
               "summarizeBy": "none"
           },
           {
               "name": "#{DevName}#",
               "dataType": "int64",
               "sourceColumn": "CustomerNumber",
               "summarizeBy": "none",
               "isHidden": #{trueifdev}#
           }
    ],
    "partitions": [{
        "name": "Partition",
        "dataView": "full"
    }]
  },
}

The format of variable in .json file is #{DevName}# & #{trueifdev}#.

Copy this file to the artifact and use Replace Tokens task to update the key's values:

enter image description here

And define the key's values on the Variables based on the stages:

enter image description here

As test result for stage Stage:

       {
           "name": "TDev456",
           "dataType": "int64",
           "sourceColumn": "CustomerNumber",
           "summarizeBy": "none",
           "isHidden": False
       }

The key's values name & isHidden have been updated to TDev456 & False.

Hope this helps.