Search code examples
azureazure-devopsazure-pipelinesdevopsazure-devops-rest-api

Disable Continuous Integration on Pipeline using the Azure DevOps REST API


I'm using the pipeline REST endpoint documented here to create my pipelines and associate them with a YAML file. On some of my pipelines I want to have continuous integration disabled. On the DevOps portal you can do that here:

enter image description here

I would like to automate this as part of my process but I do not see anything in the official documentation.

I have tried passing in what I see the portal doing when I inspect the payloads being sent from the UI by adding an empty triggers array to the configuration property in my payload when calling the Pipelines - Create endpoint but this seems to be ignored.:

"triggers":[]

Here is a complete payload example:

{
  "configuration": {
    "variables": {
      "VARIABLE_NAME": {
        "isSecret": false,
        "value": "Value"
      }
    },
    "type": "yaml",
    "path": "azure-pipelines.yml",
    "repository": {
      "id": "repo-id",
      "type": "azureReposGit",
      "name": "repo-name"
    },
    "triggers": []
  },
  "name": "Production"
}

Is there a way to override/disable the CI settings on my YAML file through the REST API or is this only something that can be achieved through the UI?


Solution

  • According to this SO thread answer by Krzysztof Madej you need to use Update Definition API and set the value of queueStatus as Disabled. Or use Create Definiton API and set the value of queueStatus as Disabled. Definiton API reference- Definitions - REST API (Azure DevOps Build) | Microsoft Learn

    As Create/Get Pipeline API does not contain queueStatus value in the output, Refer below :-

    Powershell code: -

    API Reference- Pipelines - Get - REST API (Azure DevOps Pipelines) | Microsoft Learn

    $PAT = "xxxxxxxxxa4gzoia"
    $OrgName = "sid24desai0738"
    $ProjectName = "AzureDevops"
    $ApiVersion = "7.0"
    
    # Retrieve pipelines information
    $pipelines = Invoke-RestMethod -Uri "https://dev.azure.com/$OrgName/$ProjectName/_apis/pipelines/257?api-version=7.1-preview.1" -Method Get -Headers @{Authorization=("Basic {0}" -f [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$PAT")))}
    
    # Output pipelines information
    $pipelines
    

    Output: -

    enter image description here

    You can check the queueStatus by calling the Get Definitons API from above Definiton API reference link [Get]:-

    Powershell code: -

    $PAT = "hxxxxxxxxwa4gzoia"
    $Organization = "sid24desai0738"
    $Project = "AzureDevops"
    $ApiVersion = "7.1-preview.7"
    
    # Construct the URI
    $Uri = "https://dev.azure.com/$Organization/$Project/_apis/build/definitions?api-version=$ApiVersion"
    
    # Make the GET request to retrieve build definitions
    $response = Invoke-RestMethod -Uri $Uri -Method Get -Headers @{
        Authorization = "Basic " + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$PAT"))
    }
    
    # Output the response
    $response.value
    

    Output:-

    enter image description here