Sunday, September 17, 2017

How to trigger a azure web job from a web hook using powershell



$xmlProfile = [xml](Get-AzureRMWebAppPublishingProfile -ResourceGroupName "delete" -Name"testwebgirish" -OutputFile test.xml)
$userName = $xmlProfile.publishData.publishProfile[0].userName.Tostring()
$userPWD = $xmlProfile.publishData.publishProfile[0].userPWD.Tostring()
$url = $webJobs.url
$index = $url.IndexOf('triggeredwebjobs')
$webJobUrl = $url.Substring(0,$index+ "triggeredwebjobs/"
$webHookUrl = $webJobUrl + $webJobs.name + "/run"
$request = [System.Net.WebRequest]::Create($webHookUrl)
#$pair = "$userName"+":"+$userPWD+"
$auth =[System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($userName+":"+$userPWD))
$request.Method = "POST"
$request.ContentLength = 0;
$request.Headers["Authorization"] = "Basic " + $auth
$response = $request.GetResponse()
$responsestream = $response.GetResponseStream();
[System.IO.StreamReader] $streamReader = New-Object System.IO.StreamReader -argumentList$responsestream;
[string] $results = $streamReader.ReadToEnd();

No comments:

Post a Comment