Search code examples
azureazure-devopsazure-functionsazure-pipelinesazure-cli

Create Dockerised Function CD Webhook in Azure CLI


So I'm trying to create a dockerised functionapp that when the docker image is updated in an ACR, the function is reloaded with the new image.

So I've created the functionapp:

az functionapp create --name $(functionDockerAppName) --storage-account $(dockerStorageAccountName) --resource-group $(resourceGroupName) --plan $(dockerStorageAccountName) --deployment-container-image-name $(dockerRepoUrl)/$(dockerTag):$(dockerVersion) --functions-version 4 --os-type Linux 

Enabled CD for the functionapp:

az functionapp deployment container config --enable-cd --name $(functionDockerAppName) --resource-group $(resourceGroupName)

And now I'm trying to create the webhook for that:

az acr webhook create --name $(functionDockerAppName)CD --actions push --registry $(registryName) --uri "$(az functionapp deployment container show-cd-url --name $(functionDockerAppName) --resource-group $(resourceGroupName) | jq .CI_CD_URL)"

The subcommand seems to evaluate correctly, however I get this error:

Service URI "https://$name-redacted:token-redacted@name-redacted.scm.azurewebsites.net/docker/hook" for the webhook name-redacted is an invalid URI

Where name-redacted in that quote is equal to $(functionDockerAppName)CD.

The weird thing is, if I take that URI and enter it as the service URI in the portal, it works.

What's the problem here?


Solution

  • I've worked it out myself.

    The issue is that my subcommand returns the URI wrapped in speech marks... The AZ CLI doesn't like this.

    It works if we strip them off.

    So if we use tr to do this trimming we get a final command of:

    az acr webhook create --name $(functionDockerAppName)CD --actions push --registry $(registryName) --uri "$(az functionapp deployment container show-cd-url --name $(functionDockerAppName) --resource-group $(resourceGroupName) | jq .CI_CD_URL | tr -d \")"