Run triggered Azure WebJob from Code
You could trigger the WebJob via the WebJob API. C# code included in the following post:
http://chriskirby.net/blog/running-your-azure-webjobs-with-the-kudu-api
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("https://mysiteslot.scm.azurewebsites.net/api/");
// the creds from my .publishsettings file
var byteArray = Encoding.ASCII.GetBytes("username:password");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
// POST to the run action for my job
var response = await client.PostAsync("triggeredwebjobs/moJobName/run", null)
As Justin said, we can use WebJob API to achieve this requirement. We could find this KUDU API at: https://github.com/projectkudu/kudu/wiki/WebJobs-API. Below is my tested code:
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("https://<web appname>.scm.azurewebsites.net/api/triggeredwebjobs/<web job name>/run");
request.Method = "POST";
var byteArray = Encoding.ASCII.GetBytes("user:password"); //we could find user name and password in Azure web app publish profile
request.Headers.Add("Authorization", "Basic "+ Convert.ToBase64String(byteArray));
request.ContentLength = 0;
try
{
var response = (HttpWebResponse)request.GetResponse();
}
catch (Exception e) {
}
It works on my side. Hope it helps.