Igor Kurylo
Igor Kurylo

Reputation: 45

Attach bug to user story or create new user story after build success TFS On prem

I have a build on TFS and i configure if a build failed i open automatically a bugs, The question is how i attach a bug to some user story or create a new user story for bugs.

Upvotes: 0

Views: 51

Answers (1)

Shamrai Aleksander
Shamrai Aleksander

Reputation: 16018

You can consider to use PowerShell and Rest Api. This script will create a new user story from a build step:

$user = ""
$token = "$(System.AccessToken)"
$teamProject = "$(System.TeamProject)"
$orgUrl = "$(System.CollectionUri)"

$type = "User Story"
$witTitle = "From my build"


$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$createWIUrl = "$orgUrl/$teamProject/_apis/wit/workitems/$" + $type + "?api-version=5.1"
$body="[
  {
    `"op`": `"add`",
    `"path`": `"/fields/System.Title`",
    `"value`": `"$($witTitle)`"
  }
]"

$result = Invoke-RestMethod -Uri $createWIUrl -Method POST -ContentType "application/json-patch+json" -Body $body -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}

Write-Host $result

You can add additional information from build variables into your title or description.

Upvotes: 1

Related Questions