Azure runbook to Azuredevops server pipeline trigger failing

105 Views Asked by At

We are following the answer provided in stackoverflow and trying to automate the secret expiry notification of our key vaults and enable auto rotation of secrets using azuredevops pipelines.

We are getting "No such host is known" error while we are trying to invoke the azuredevops server pipeline hosted in on premise from the azure runbook automation script.

param
(
[Parameter (Mandatory = $false)]
[object] $WebhookData
)

#If runbook was called from Webhook, WebhookData will not be null.
if ($WebhookData) {
#Run Azure DevOps REST API to trigger the pipeline
$token = "xxxxxxxxxxxxxxxxxxxxx"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
$url = "https://myado.com/devops/myorganization/myproject/_apis/build/builds?api-version=6.0"
$body = @"
{
    `"definition`":  {
                       `"id`":  xxxxx
                   }
}
"@
$head = @{ Authorization =" Basic $token" }
Invoke-RestMethod -Uri $url -Method Post -Headers $head -Body $body -ContentType application/json
}
else
{
# Error
write-Error "No input data found." 
}
1

There are 1 best solutions below

6
On

The request URI is in the following form:

VERB https://{instance}[/{team-project}]/_apis[/{area}]/{resource}?api-version={version}.

For Azure DevOps server, the instance is {server:port}/tfs/{collection}. See Components of a REST API request/response pair for the detailed info.

Take my server as an example. The following is the URL of the project seen on the UI. enter image description here

Copy the URL directly from the brower and the request URL will be http://vziy***/DefaultCollection/Pro1/_apis/build/builds?api-version=6.0