How can we enable/disable a Azure DevOps Pipeline using Azure Devops rest api or CLI commands

4.9k Views Asked by At

I'm trying to enable/disable multiple pipelines based on a condition, would like to create a pipeline that takes the parameter from the user and updates all the other pipelines.

I've found these below documents from Microsoft
https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/pipelines?view=azure-devops-rest-6.0 https://learn.microsoft.com/en-us/cli/azure/ext/azure-devops/pipelines?view=azure-cli-latest

but I'm not able to find anything for enabling/disabling a pipeline, is there any way of doing this in any other ways?

1

There are 1 best solutions below

4
On

I'm not able to find anything for enabling/disabling a pipeline, is there any way of doing this in any other ways?

You can use the REST API Definitions - Update to enable or disable pipelines.

PUT https://dev.azure.com/{organization}/{project}/_apis/build/definitions/{definitionId}?api-version=6.0

For its request body, you need to get the definition of the build using the GET REST API first:

GET https://dev.azure.com/{organization}/{project}/_apis/build/definitions/{definitionId}?api-version=6.0

Use the response body of GET REST API as the request body of PUT REST API. And then modify the value of queueStatus according to your requirements.

If you want to enable the pipeline, set the value of queueStatus to enabled; If you want to disable the pipeline, set the value of queueStatus to disabled.