Skip to content

Instantly share code, notes, and snippets.

@MarcusFelling
Last active May 19, 2019 19:18
Show Gist options
  • Save MarcusFelling/968c78c366272b69e032225169e1edf4 to your computer and use it in GitHub Desktop.
Save MarcusFelling/968c78c366272b69e032225169e1edf4 to your computer and use it in GitHub Desktop.
using namespace System.Net
# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)
# Write to the Azure Functions log stream.
"PowerShell HTTP trigger function processed a request."
# Get Personal Access Token (PAT) from query parameter of the request.
$PAT = $Request.Query.PAT
if (-not $PAT) {
$PAT = $Request.Body.PAT
}
if ($PAT) {
$status = [HttpStatusCode]::OK
$body = "Using Personal Access Token (PAT) passed in query string.`n"
}
else {
$status = [HttpStatusCode]::BadRequest
$body = "Please pass a Personal Access Token (PAT) on the query string."
}
# Base64-encodes the Personal Access Token (PAT) appropriately
# This is required to pass PAT through HTTP header
$script:User = "" # Not needed when using PAT, can be set to anything
$script:Base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $User,$PAT)))
# Get list of all release definitions from Azure DevOps project
[uri] $script:GetReleaseDefinitionsURI = "https://vsrm.dev.azure.com/marcusfelling/personal/_apis/Release/definitions"
# Invoke the REST call and capture the response
$GetReleaseDefinitionsResponse = Invoke-RestMethod -Uri $GetReleaseDefinitionsURI -Method Get -Headers @{Authorization=("Basic {0}" -f $Base64AuthInfo)}
# Add response to body of Function response
$body += "List of Release Definitions: `n"
$body += $GetReleaseDefinitionsResponse.value.name
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = $status
Body = $body
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment