Search code examples
azureazure-rm-template

Error when deploying custom template in Azure from Azure DevOps repo ("deploy to azure" button)


All,

I'm trying to use the "deploy to Azure" button, using a template stored in Azure DevOps Git repo.
I'm receiving the following error:
Error parsing template. Please ensure template is valid JSON. Invalid symbol at character position 4. (3 other errors).

I created the URL following what is described in https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/deploy-to-azure-button.

My structure is the following:

  • Azure DevOps organization = MyOrganization and project is myProject
  • Repo is myRepo, and the template file is on branch myBranch, located at myFolder/myTemplate.json.

At the end, the URL looks like
https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fdev.azure.com%2F{myOrganization}%2F{myProject}%2F_apis%2Fgit%2Frepositories%2F{myRepo}%2Fitems%3Fpath%3D%2F{myFolder}%2F{myTemplate}.json%26versionDescriptor.version%3D{myBranch}%26versionDescriptor.versionType%3Dbranch%26api-version%3D6.0

Copy/pasting this URL in a browser returns the above error...

I believe my JSON file is correct (no error) because it works fine in the following two situations:

  • if using the same JSON template file with Azure CLI (az deployment groupe create --template-file <myJSONtemplatefile> --parameters <myJSONparametersfile>
  • if copy/pasting the JSON template file in Azure portal for custom deployment at https://portal.azure.com/#create/Microsoft.Template

I don't get what is the reason of the Error parsing template...


Solution

  • Found!
    Issue was due to the fact that the AzDO repo is private, and not public.
    This was clearly stated in Microsoft documentation, but I missed it... (bolding word is mine)

    If you're using Git with Azure Repos instead of a GitHub repo, you can still use the Deploy to Azure button. Make sure your repo is public. Use the Items operation to get the template.

    With a public AzDO repo, everything works like a charm.