Automated Pipeline Setup

According to Azure DevOps pipeline it will be written in yaml. Task will use PowerShell script to do updates on work items.

variables:
- group: YourVariableGroupName
# in this library we will hold Personal Access Token

jobs:
- job: Automated_Pipeline
  displayname: Automated Pipeline

  steps:
  - checkout: self
    fetchDepth: 1
    persistCredentials: True

  - task: PowerShell@2
    displayName: Update work items
    inputs:
      targetType: filePath
      filePath: 'PathToYourFolder/PowerShellFile.ps1'
      pwsh: true
    env:
      AZURE_DEVOPS_EXT_PAT: $(YourVariableWithPAT)

PowerShell script

To connect to Azure DevOps CLI use this command at the begining of script:

az devops configure --defaults project='Your Project Name' organization=<link to your organization on https://dev.azure.com>

Afterwards you are ready to go and use Azure DevOps CLI to operate on your work items.

  • Query your work items example
$query = "SELECT [System.Id] FROM workitems WHERE [System.WorkItemType] = 'Bug' AND [System.State] = 'New' ORDER BY [System.Id]"

$search = $(az boards query --wiql "${query}" --output json --only-show-errors)

$jsonObject = $search | ConvertFrom-Json

foreach ($item in $jsonObject)
{
  Write-Host "Work item #${$item.id}"
}
  • Update your work item field example
$update = $(az boards work-item update --id $($item.id) --fields "Custom.YourCustomField=YourText" --only-show-errors)
  • Checking relations of your work items examples
# checking if your work item has a Successor
$query = "relations[?rel=='Successor'].{url:url}"

$length = $(az boards work-item relation show --id $($item.id) --query $query --output tsv --only-show-errors)
# checking your Parent id and work item type
$query = "[fields.\`"System.Parent\`", fields.\`"System.WorkItemType\`"]"

$validation = $(az boards work-item relation show --id $($item.id) --query $query --output tsv --only-show-errors)

if (($validation[0] -eq 12345) -and ($validation[1] -eq "Feature"))
{
  # do what you want with work item 
}

Update Boards Process

Additionaly you can update your work items type process:

  • You can add additional custom fields to your work item type
  • You can orginize your work item layout
  • You can edit states of your work items type
  • You can add custom rules to your work item type to cooparate with automated mechanism

To do this you need to go to your Azure DevOps project site:

  • Choose Organization settings
  • Choose Boards -> Process
  • Choose Process to change
  • Choose work item type to change

Leave a Reply

Discover more from mieszkoitblog

Subscribe now to keep reading and get access to the full archive.

Continue reading