2

Deploying Azure function using KUDU api

This is my url:

$apiUrl = 'https://myapp.scm.azurewebsites.net/api/zipdeploy?isAsync=true'

Invoke rest method script :

Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -UserAgent $userAgent -Method POST -InFile $zipFile -ContentType "multipart/form-data" -OutFile sample.txt -Verbose 

Output I am getting:

VERBOSE: POST https:// myapp.scm.azurewebsites.net /api/zipdeploy?isAsync=true with -1-byte payload
VERBOSE: received 0-byte response of content type  

Here my issue is I am not getting any response back and the sample.txt is an empty file. While using the url without isAsync I am getting a time out exception in teamcity that’s why I went for Async deployment

I can verify the portal to see that the deployment is success but how is it possible through the powershell script to verify the deployment status.

In the following site it is mentioned like this :

Async support: By adding ?isAsync=true to the URL, the deployment will run asynchronously. The Location header of the response will contain the deployment URL that can be polled for deployment status. Webhooks can be used for fully asynchronous notification of completion.

https://github.com/projectkudu/kudu/wiki/Deploying-from-a-zip-file

In this document it is mentioned like this -

The Location header of the response will contain a link to a pollable deployment status.

But I don't know how to get the location header. Please help.

Aathira
  • 655
  • 3
  • 14
  • 31

1 Answers1

3

Crazy enough, Invoke-RestMethod doesn't seem to return a headers object, however, Invoke-WebRequest does. You should be able to rewrite your request to use the latter with minimal effort.

You can then access the headers as follows:

PS> $headers = Invoke-WebRequest -Uri https://jsonplaceholder.typicode.com/posts/1 | 
                   select -expand Headers

PS> $headers

Key                              Value
---                              -----
Connection                       keep-alive
Vary                             Origin, Accept-Encoding
...
Server                           cloudflare
...

PS> $headers.Server
cloudflare

Coming back to Invoke-RestMethod, this PR has been merged into PowerShell but i guess it's just in Core not in Windows PowerShell (the full Framework one).

You could install PowerShell Core 6.0 (works side-by-side with Windows PowerShell) to use that new -ResposneHeadersVariable parameter, it's probably more sensible to just switch to Invoke-WebRequest.

Here's your request on PowerShell Core 6.1.0-preview2 (should work with stable releases as well, anything after Sep 25, 2017):

PS C:\Program Files\PowerShell\6-preview> Invoke-RestMethod `
        https://jsonplaceholder.typicode.com/posts/1 -ResponseHeadersVariable headers

PS C:\Program Files\PowerShell\6-preview> $headers

Key                              Value
---                              -----
Cache-Control                    {public, max-age=14400}
Connection                       {keep-alive}
Date                             {Fri, 11 May 2018 07:11:05 GMT}
Pragma                           {no-cache}
...

According to this blog post there's no future for Windows PowerShell, all efforts are now on PowerShell Core.

evilSnobu
  • 24,582
  • 8
  • 41
  • 71
  • 1
    Invoke-WebRequest helped to resolve the issue. The following link was helpful while creating the header. (https://stackoverflow.com/a/27951845/5810078) – Aathira May 15 '18 at 06:12