skip to Main Content

I have created variable groups in Azure library and link in Azure pipeline. How to initialize xxx.json file? Update variables of xxx.json file in react and .NET project.

I added variables in library group and link this variable group to Azure pipeline. To use a variable from a variable group, you need to add a reference to the group in your YAML file:

variables:

- group: my-variable-group

Thereafter variables from the variable group can be used in your YAML file.

This is the xxx.json in code:

{
    "API_ENDPOINT": "https://api.example.com",
    "https://localhost"
}

How to update values for Azure variable group?

2

Answers


  1. You can use Azure DevOps Replace Tokens task in your pipeline and do the token replacement in your configuration files during your Azure Pipeline run.

    First define Tokens in your configuration file:

    {
        "API_ENDPOINT": "__API_ENDPOINT__"
    } 
    

    Then your task will search for tokens with the specified prefix in the specified files and replace them with corresponding variable values from your variables.

    Here you have an article how to deal with token replacement.

    Login or Signup to reply.
  2. You may add the simple PowerShell script:

    $filepath = "$(system.defaultworkingdirectory)/xxx.json"
    
    ((Get-Content -path $filepath -Raw) -replace '__API_ENDPOINT__','$(VARIABLE_NAME)') | Set-Content -Path $filepath 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search