azure-devopsazure-devops-rest-apiazure-devops-deploymentgroups

how to get deployments for selected machine in Azure devops deployment groups using rest api


I am working on script to get deployment from Azure DevOps for selected Azure DevOps Deployment group and Selected target machine

following Used rest api url does not provide required data -

$connectionToken = ""

$Url1 = "https://dev.azure.com/{Org Name}{Project Name}/_apis/distributedtask/deploymentgroups? 
name={name}&api-version=6.0-preview.1"

$base64AuthInfo= 
[System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))

$json = Invoke-RestMethod -Uri $Url1 -Headers @{authorization = "Basic $base64AuthInfo"} -Method Get

$data = $json | ConvertTo-Json -Depth 100 

$data

What rest api url changes I need to do for getting required data ?


Solution

  • What rest api url changes I need to do for getting required data ?

    You could try the following URL to get the deployment Jobs :

    https://dev.azure.com/{OrganizationName}/{ProjectName}/_apis/distributedtask/deploymentgroups/{DeployGroup ID}/deploymentTargetJobRequests?targetId={TargetMachineID}&api-version=6.1-preview.1
    

    You could get the deploygroup id and target machine id in the Azure Devops url:

    enter image description here

    mgid = deploygroup id machineid = target machine id.

    Here is the Powershell Example:

    $connectionToken = "PAT"
    
    $Url1 = "https://dev.azure.com/{OrganizationName}/{ProjectName}/_apis/distributedtask/deploymentgroups/{DeployGroup ID}/deploymentTargetJobRequests?targetId={TargetMachineID}&api-version=6.1-preview.1"
    
    $base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))
    
    $json = Invoke-RestMethod -Uri $Url1 -Headers @{authorization = "Basic $base64AuthInfo"} -Method Get
    
    $data = $json | ConvertTo-Json -Depth 100 
    
    $data
    

    Result:

    enter image description here