0

I need to setup an Azure DevOps service connection of type "Python Package Download" in multiple projects and so I want to do it programmatically.

I was looking at the Azure DevOps Terraform provider but it seems that this type of service connection is not supported. Is my assumption correct about this type of service connections related to terraform?

If so what is the best other alternative resp. has anyone an example Azure DevOps REST API call for the creation of such service connections?

Thank you

0

1 Answer 1

1

You can use Endpoints - Create - REST API (Azure DevOps Service Endpoint) to create a service connection with "Python Package Download" type in Azure DevOps.

Here is an example of calling the REST API using PowerShell:

# Convert PAT to a Base64 string.
$pat = "{Personal Access Token}"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "", $pat)))

# Set request headers.
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", ("Basic {0}" -f $base64AuthInfo))
$headers.Add("Content-Type", "application/json-patch+json")

$uri = "POST https://dev.azure.com/{organization}/_apis/serviceendpoint/endpoints?api-version=7.0"

# Set request body and convert it to JSON type.
$body = @(
    @{
  "name": "MyNewServiceConnectionName",
  "type": "PythonPackageDownload",
  "url": "https://myserver",
  "authorization": @{
    "parameters": @{
      "username": "myusername",
      "password": "mysecretpassword"
    },
    "scheme": "UsernamePassword"
  },
  "isShared": false,
  "isReady": true,
  "serviceEndpointProjectReferences": [
    @{
      "projectReference": @{
        "id": "ProjectId",
        "name": "ProjectName"
      },
      "name": "MyNewServiceConnectionName"
    }
  ]
}
    ) | ConvertTo-Json -Depth 100

# Execute Invoke-RestMethod cmdlet to call the API and convert it response to JSON for better readable.
Invoke-RestMethod -Method POST -Uri $uri -Headers $headers -Body $body | ConvertTo-Json -Depth 100
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.