0
votes

I want to modify the service endpoint of a pipeline in Azure DevOps via API.

Example:

Pipeline "build-a-release" uses my personal service endpoint "hello1". But I want it to use existing service endpoint "my-companys-global-service-endpoint" instead.

The documentation https://docs.microsoft.com/en-us/rest/api/azure/devops/pipelines/pipelines?view=azure-devops-rest-6.0 does not show any "update" function, but I can update the service endpoint of a pipeline in the Azure DevOps GUI.

How can I automate this process via a script and API?

Change the service endpoint of a pipeline via the GUI

1

1 Answers

2
votes

To update a service endpoint, you should use Endpoints - Update Service Endpoint API:

PUT https://dev.azure.com/{organization}/_apis/serviceendpoint/endpoints/{endpointId}?api-version=6.0-preview.4

To update a pipeline defintion, you could use Definitions - Update api to update it. When you capture the network log, you could see there is connectedServiceId in properties of repository parameter. You could update the connectedServiceId to change the service connection.

From my test, something you need to notice:

  1. Make sure the request headers include the following items:

enter image description here

  1. Make sure you have the correct "revision" value (the latest revision) in the body.