Menu

Azure DevOps – Calling REST endpoint via Powershell script

As part of the CI/CD, I had run the migrations I created with TypeORM (NodeJs), I have selected the path of creating a function that runs the script. Endpoint needs to be called once the app deployment is completed.

Add a Powershell script with

First, you need to run, so you will not get certificate errors, etc.

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12

Then the Invoke-RestMethod with parameters

$url = "https://func-myfunction-dev.azurewebsites.net/api/actions"
$headers = @{ 'Content-Type' = 'application/json'; 'x-functions-key' = '$(ACTION_FUNCTION_KEY)'}
$body = '{ "actionType":"Migrate" }'
Invoke-RestMethod -Method 'Post' -Uri $url -Headers $headers -Body $body

This is the full script

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12
$url = "https://func-profileapp-dev.azurewebsites.net/api/actions"
$headers = @{ 'Content-Type' = 'application/json'; 'x-functions-key' = '$(ACTION_FUNCTION_KEY)'}
$body = '{ "actionType":"MigrateDatabase" }'
Invoke-RestMethod -Method 'Post' -Uri $url -Headers $headers -Body $body

 

Leave a comment