1
votes

I want to know if writing PowerShell to create Azure DevOps service connection endpoints is possible.

I want to restrict access to everyone to create service connection endpoints by visiting Azure DevOps and we require multiple service connection endpoints to be created including connection endpoint for UnitTesting tool, Build tools, Automation testing tool and then docker things.

I can read already created Azure DevOps service connection endpoints through Azure DevOps Rest API using PowerShell (Invoke-RestMethod <uri> -Method get -Header <myheader>) however I want to know if it is possible to create new service connection endpoint using the same Rest API by passing service endpoint information as Body to the Rest API (Invoke-RestMethod).

This is how I can get the existing service connection endpoints:

##Invoke-RestMethod $url -Method GET -Headers $headers -ContentType 
'application/json' -Verbose

##I refer below code as Example to code to update existing work item, 
this is working but for service connection endpoint, I'm having no clue:
$workitem = Invoke-RestMethod -Uri $wisUrl -Method Get -ContentType 
"application/json" -Headers $header
Write-Host "Before: $($workitem.fields.'System.Title')"

$body = @" 
[
  {
    "op": "add",
    "path": "/fields/System.Title",
    "value": "$($workitem.fields.'System.Title')+DEMO"
  },
  {
    "op": "add",
    "path": "/fields/System.History",
    "value": "Changing Title"
  }
] 
"@

$workitem = Invoke-RestMethod -Uri $wisUrl -Method Patch -ContentType 
"application/json-patch+json" -Headers $header -Body $body
Write-Host "After: $($workitem.fields.'System.Title')"
1

1 Answers

0
votes

It's possible with Endpoints - Create Rest API:

POST https://dev.azure.com/{organization}/{project}/_apis/serviceendpoint/endpoints?api-version=5.1-preview.2

Request body, for example (for Azure endpoint):

{
  "data": {
     "SubscriptionId": "21312421-4123-1323-3123-12534543",
     "SubscriptionName: "TestSub"
  },
  "id": "2e344hjds-23ds-242fs-42ds-dsfsdaf34s",
  "name": "TestEndpoint",
  "type": "Azure",
  "authorization": {
    "parameters": {
       "Certificate": "dummyCertificate"
     },
     "scheme": "Certificate"
  },
  "isReady": false
}