1
votes

I have an ARM template that creates, among other resources, a web site that hosts a webjob and a job that is part of a scheduler. I have managed to get everything configured through the ARM template except for the authentication.

When the job needs to run, it creates an HTTP request that should kick off the webjob. Unfortunately, the webjob is never started. If I go into the Azure portal and update the settings for the job (Action settings) and configure Basic authentication (with the deployment credentials) everything starts working as expected, but I'm not sure how I can retrieve those credentials from the ARM template. I could run it once, create the web site, get the credentials then update the ARM template, but that defeats the whole reason I'm building the ARM template in the first place.

1

1 Answers

6
votes

I found an answer that got me most of the way there; you can set the Uri of the request to list(resourceId('Microsoft.Web/sites/config', variables('webSiteName'), 'publishingcredentials'), '2016-08-01').properties.scmUri. You will also need to concatinate the rest of the path (e.g. /api/triggeredwebjobs/{webjobname}/run)

The Uri produced by the above code includes the basic auth credentials, and that is parsed at some point and the username and password are taken out of the Uri so they aren't visible in the Azure portal and the authentication is set to 'Basic', and the credentials are set to the extracted values.

However, my Uri had query string appended to the end to pass parameters into the webjob. During the deployment process, the query string gets mangled (the question mark is escaped to %3F and if you have any escaped characters in your arguments value, they will get unescaped.

I managed to work around this by concatinating strings together to make up the Uri (NOT using the scmUri property), and then setting the authentication property, which is a sibling to the uri property to look like the following

"authentication": { "type": "Basic", "username": "[list(resourceId('Microsoft.Web/sites/config', variables('webSiteName'), 'publishingcredentials'), '2016-08-01').properties.publishingUserName]", "password": "[list(resourceId('Microsoft.Web/sites/config', variables('webSiteName'), 'publishingcredentials'), '2016-08-01').properties.publishingPassword]" }