I have a love hate with the Azure portals. Some days it's fast and lets me do exactly what I want, other days like today, I just want more control over how my stuff runs. The Stuff I'm referring to here are the many WebJobs I've deployed to Azure since they released the feature and SDK many months ago. I've written in a previous post on how you could automate the deployment and scheduling of your jobs, but now I want to move a few steps beyond that. Notably, I want to run my triggered jobs on-demand from my own interfaces and I want the potential to update them as well. Luckily this is possible using the Kudu WebJobs REST API. Kudos to the Kudu team (eh??) for creating some great documentation to get me started!
In this post I'm going to focus on simply running my jobs on-demand outside of the Azure portal. In this example, I've already uploaded my WebJob via zip file or as part of my deployment to Azure, so it is ready and waiting to be run.
Get your creds
The simplest way I've found to authenticate against the API is to use my sites WebDeploy deployment credentials. You can download them from your web app's dashboard in either portal, look for: "Get||Download publish profile". The downloaded
.publishsettings file should looks something like this:
The parts your interested in are the
userPWD on the
<publishProfile> element for the Web Deploy credentials. You'll use these to authenticate using basic authentication against the API.
Run your WebJob
In code, I'm using HttpClient to create a new POST request using Basic Auth:
In Postman, I'm building a new POST request to
https://mysiteslot.scm.azurewebsites.net/api/triggeredwebjobs/moJobName/run and adding Basic Auth under the Authorization tab using the credentials from my
If successful, expect a 202 Accepted response with no body from the server and your job to be running.
Get your job's history
Finally, you may want to check the status of your job, especially if its long running, or just make sure it ran successfully. A simple call to
/api/triggeredwebjobs/myJobName/history will return the following JSON: