Generating Simple Octopus Release notes from VSO REST

One of the common issue’s I’ve had is when using octopus marking in the release notes “whats new” in this version.

Weather pushing from TeamCity or team build the issue is the same.

So here’s some powershell i use in a “PowerShell” build step in TeamCity to generate basic “Work item” plus “Change Set” lists with links through to Visual Studio Online.

You will need to add some variables into you parameters and pass them through into the script. For the from and to change set IDs you can use these two from TeamCity

%build.vcs.number% %build.vcs.number.1%

To setup Basic Auth Creds check here https://www.visualstudio.com/en-us/integrate/get-started/auth/overview


#======================
param(
[string]$account,
[string]$username,
[string]$password,
[string]$fromID,
[string]$toID
)
#======================

Write-Host "Starting Writing Release Notes"
$basicAuth = ("{0}:{1}" -f $username,$password)
$basicAuth = [System.Text.Encoding]::UTF8.GetBytes($basicAuth)
$basicAuth = [System.Convert]::ToBase64String($basicAuth)
$headers = @{Authorization=("Basic {0}" -f $basicAuth)}
$cs = Invoke-RestMethod -Uri "https://$account.visualstudio.com/DefaultCollection/_apis/tfvc/changesets?fromId=$fromID&toId=$toID&api-version=1.0" -headers $headers -Method Get

$wiIDs = @()

$releaseNotesCS=""
$releaseNotesWI=""

foreach($c in $cs.value)
{
$urlvar = $c.url
$s = Invoke-RestMethod -Uri $urlvar"?includeWorkItems=true&api-version=1.0" -headers $headers -Method Get

$releaseNotesCS += "<a href='https://$account.visualstudio.com/DefaultCollection/SOS/_versionControl/changeset/" + $s.changesetId + "'>" + $s.changesetId + "</a> " + $s.comment +"`r`n
";
Write-Host $s
foreach ($wi in $s.workItems)
{
if($wiIDs.Contains($wi.id))
{
Write-Host "In Array Already";
}
else
{
$releaseNotesWI += "<a href='" + $wi.webUrl + "'>" + $wi.id + "</a> " +$wi.title + " (" + $wi.state + ")`r`n
";
Write-Host $wi;
}
}
}

$releaseNotesWI+"
"+$releaseNotesCS | out-file ".\ReleaseNotes.html"
Write-Host "Finished Writing Release Notes"

Then in your octopus step simply set “Additional command line arguments”

–ReleaseNotesFile=ReleaseNotes.html

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s