Search code examples
azure-devopscontinuous-integrationdevopsazure-pipelines-release-pipeline

Azure DevOps: 'Replace Tokens task' having problem setting variable files from JSON


I'm trying to setup a 'Replace Tokens Task' for my build pipeline from a JSON file that will hold environmental variables as follow:

enter image description here

And then my JSON environment file:

enter image description here

The JavaScript target file to replace the tokens in:

enter image description here

Unfortunately, I'm getting the following error:

enter image description here

What am I missing here?


Solution

  • What am I missing here?

    enter image description here

    I can reproduce same issue on my side, and I think it only indicates there's something wrong with your Variable files(JSON) input:

    enter image description here

    Please make sure the variables are successfully loaded from the variable json file.

    1.Make sure your env-config.json file has content below:

    {
        "alambda.endpoint":"ForTest"
    }
    

    2.Check carefully about the path of your env-config.json file! (In my opinion, your issue is more like a path issue~) If the task can't find and load the file, it also throws variable not found. For this:

    • Make sure the relative path is correct.
    • Try cut the long path, I'm not sure if the issue results from the too long path. Try using **/env-config.json instead of the very long path.
    • If above tips can't work, I suggest you can move the env-config.json file to root folder $(System.DefaultWorkingDirectory) with Copy Task or what. (About System.DefaultWorkingDirectory see here). Then try it again with **/env-config.json.