未加星标

Update Work Items with Build Number During vNext Builds

字体大小 | |
[系统(windows) 所属分类 系统(windows) | 发布者 店小二05 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

In the days of XAML Builds in TFS, the build would rather handily update the work item with the appropriate “Integration Build” value… so you knew which release would include your fix. Happy days.

Along came vNext builds in TFS / Visual Studio Online / Visual Studio Team Services, which solved all of the pain of setting up and maintaining builds, but which also didn’t update the “Integration Build” value on the work items.

The good news is, we can handle this in vNext builds using the Team Services REST API for Work Items .

Here’s how…

Security

You can generate a special token to use for this so you don’t need to use your actual account.

Click your name when logged into the VSTS Choose “Security” Select “Personal Access Tokens” Select “Add” Call it “Update Integration Build” and select the Build (read) and Work items (read and write) scopes Click “Create Token”

You’ll use this token to talk to the REST API.

PowerShell Script

You’ll need to add the following PowerShell script into your code repository, so it is available during the build.

param(
$Username,
$Password
)
$token = ("{0}:{1}" -f $Username, $Password)
$tokenBytes = [System.Text.Encoding]::UTF8.GetBytes($token)
$authorization = [System.Convert]::ToBase64String($tokenBytes)
$headers = @{Authorization=("Basic {0}" -f $authorization)}
[String] $collectionAddress = "$env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"
[String] $project = "$env:SYSTEM_TEAMPROJECT"
[String] $buildId = "$env:BUILD_BUILDID"
[String] $buildNumber = "$env:BUILD_BUILDNUMBER"
Try
{
$WorkItemAddress = $collectionAddress + $project + "/_apis/build/builds/" + $buildId + "/workitems?api-version=2.0"
Write-Output "Getting Work Items from $WorkItemAddress"
$Response = Invoke-RestMethod -Uri $WorkItemAddress -ContentType "application/json" -Headers $headers -Method GET
$workItemCount = $Response.count
$workitemUrlArray = $Response.value
Write-Output "$workItemCount work items are available to update"
for($i = 0; $i -lt $workItemCount ; $i++)
{
Write-Output "Updating item $i with build $buildNumber" $workitemUrlArray[$i].url
$body = '[{ "op": "add", "path": "/fields/Microsoft.VSTS.Build.IntegrationBuild", "value":"' + $buildNumber + '"}]'
Write-Output $body
$workItemUpdateAddress = $workitemUrlArray[$i].url + "?api-version=1.0"
Invoke-RestMethod -Uri $workItemUpdateAddress -Body $body -ContentType "application/json-patch+json" -Headers $headers -Method PATCH
}
}
Catch
{
Write-Output $_.Exception | format-list -force
}

This script will dynamically obtain the base addresses of your team collection and will get the work items related to the build, and then update the “Integration Build” value.

Build Variables

Edit your vNext build and choose the “Variables” section.

Add a variable named “VstsUsername” with your username and a variable named “VstsPassword” with your newly minted token.


Update Work Items with Build Number During vNext Builds
PowerShell Build Step

Now you can add a PowerShell build step to your vNext build, calling the PowerShell script and passing the VSTS Username and Password.


Update Work Items with Build Number During vNext Builds
Magic

The next time a build triggers for a changeset that has associated work items, those work items will be updated with the build number…


Update Work Items with Build Number During vNext Builds

You can make that visible on your board, it appears in the work item details, and you can also use it in your queries and reports.

本文系统(windows)相关术语:三级网络技术 计算机三级网络技术 网络技术基础 计算机网络技术

分页:12
转载请注明
本文标题:Update Work Items with Build Number During vNext Builds
本站链接:http://www.codesec.net/view/482439.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(windows) | 评论(0) | 阅读(87)