skip to Main Content

I want list of the workItems that is changed after build in excel file.

So far I am here :

$AzureDevOpsPAT = "**********************************" 
$fromBuildId = "161" 
$toBuildId = "176"


$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($AzureDevOpsPAT)")) } 

$uriAccount ="https://AzureDevOpsServerName/DefaultCollection/ProjectName/_apis/build/workitems?fromBuildId=$($fromBuildId)&toBuildId=$($toBuildId)&api-version=5.0"

$responsewe = Invoke-RestMethod -Uri $uriAccount -Method Get -Headers $AzureDevOpsAuthenicationHeader 
$d1 = $responsewe.value | ConvertTo-Json write-host $d1
write-host $d1

Also, How can I generate release notes from these workItems ?
I am new in Powershell and DevOps too, So, any idea will be appreciated.

I have tried to Get-list of list workItems first.

2

Answers


  1. You can use below Powershell command to get the output of WorkItems between builds in csv file:-

    $PAT = "3fs6xxxxxxxxxxtyjs7cunwa"
    $OrgName = "sid24desai0738"
    $ProjectName = "AzureDevops"
    $ApiVersion = "7.0"
    
    $services = Invoke-RestMethod -Uri "https://dev.azure.com/$OrgName/$ProjectName/_apis/build/workitems?fromBuildId=1934&toBuildId=1937&api-version=7.1-preview.2" -Method Get -Headers @{Authorization=("Basic {0}" -f [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$PAT")))}
    
    # Export $services to a CSV file
    $services | Export-Csv -Path "C:templog-functionFile.csv" -NoTypeInformation
    

    Output:-

    enter image description here

    enter image description here

    Reference:-

    Builds – Get Work Items Between Builds – REST API (Azure DevOps Build) | Microsoft Learn

    Login or Signup to reply.
  2. You have used correct rest api to get the work items between builds. Now you need to export the work items to the excel, and generate release notes.

    1. Export to excel: you can use below powershell command to export to excel after rest api:
    #create the file if it doesn't exist
    $path = 'C:tempFile.csv'
    if(!(Test-Path $path)) {
        New-Item -ItemType File -Path $path -Force
    }
    
    # Export $workitems to a CSV file
    $response.value | Export-Csv -Path $path -NoTypeInformation
    
    1. Generate release notes: For generating release notes, you need to decide what information from each work item you want to include in the release notes. Once you’ve decided that, you can loop through each work item and extract the necessary information.

    The whole script sample:

    $PAT = "yourpat"
    $OrgName = "yourorgname"
    $ProjectName = "projectname"
    $buildid1 = "firstbuildid"
    $buildid2 = "secondbuildid"
    $headers = @{Authorization=("Basic {0}" -f [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$PAT")))}
    
    #get the work items between builds
    $response = Invoke-RestMethod -Uri "https://dev.azure.com/$OrgName/$ProjectName/_apis/build/workitems?fromBuildId=$buildid1&toBuildId=$buildid2&api-version=7.1-preview.2" -Method Get -Headers $headers
    
    #output the response for a check
    echo $response | ConvertTo-Json
    
    #create the file if it doesn't exist
    $path = 'C:tempFile.csv'
    if(!(Test-Path $path)) {
        New-Item -ItemType File -Path $path -Force
    }
    
    
    # Export $workitems to a CSV file
    $response.value | Export-Csv -Path $path -NoTypeInformation
    
    # get the workitem id and url for the release note as an example
    $releaseNotes = foreach ($workItem in $response.value) {
        "Work Item ID: $($workItem.id)`nURL: $($workItem.url)`n---"
    }
    $releaseNotes | Out-File -FilePath 'c:tempReleaseNotes.txt'
    
    

    enter image description here

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search