Created
September 15, 2017 12:43
-
-
Save jernejg/9ab2e9f7a23285302cc49e3addd69aff to your computer and use it in GitHub Desktop.
Powershell script that queries TeamCity for pending changes and generates a html release file with author, number of files changed, git comment and urls to matched Jira issues.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[string]$TC, #%teamcity.serverUrl% | |
[string]$TC_build_Id, #system.teamcity.buildType.id | |
[string]$outputFileName) #Output file name | |
$TC += "/guestAuth" #TeamCity needs to be running with the guest account enabled. | |
$url = "$($TC)/app/rest/changes?locator=buildType:(id:$($TC_build_Id)),pending:true" #Get pending changes for a build configuration | |
$JiraUrl = "http://yourjiraurl.com/" | |
function GetChangeDetailsUrl($changesXml) | |
{ | |
$changeIds = @() | |
Foreach ($Change in $changesXml.changes.change) | |
{ | |
$changeIds += ,@("$($TC)/app/rest/changes/id:$($Change.id)") | |
} | |
return $changeIds | |
} | |
function wrapJiraIssuesInHref ($content) | |
{ | |
#https://community.atlassian.com/t5/Bitbucket-questions/Regex-pattern-to-match-JIRA-issue-key/qaq-p/233319 | |
$issueNumber = $content -replace "((?<!([A-Za-z]{1,10})-?)[A-Z]+-\d+)","<a href=`"$($JiraUrl)`$1`">`$1</a>" | |
return $issueNumber | |
} | |
function GetFormattedChangeInfo($changeDetailsXml) | |
{ | |
$parsedMessage = wrapJiraIssuesInHref $changeDetailsXml.change.comment | |
$result = "<font color='red'><b>Author:</b></font> $($changeDetailsXml.change.user.username)" | |
$result += "<br/><b>Message:</b> <br/> $($parsedMessage)" | |
$result += "<b>Files Changed:</b> $($changeDetailsXml.change.files.count)" | |
$result += "<br><b>Commit:</b> $($changeDetailsXml.change.version)<br/><br/>" | |
$result = $result -replace "`n","</br>" -replace "`r","</br>" | |
return $result | |
} | |
$result = "<div style='font-family:Arial, Helvetica, sans-serif;font-size:9pt'>" | |
$pendingChangesXml = [xml](Invoke-RestMethod $url) | |
$changeDetailLinks = GetChangeDetailsUrl($pendingChangesXml) | |
If ($changeDetailLinks.Count -eq 0) | |
{ | |
$result += "This build contains no new code changes." | |
} | |
Foreach ($link in $changeDetailLinks) | |
{ | |
$changeDetailsXml = [xml](Invoke-RestMethod ( $link | out-string )) | |
$line = GetFormattedChangeInfo $changeDetailsXml | |
$result += "$($line)" | |
} | |
$result +="</div>" | |
New-Item $outputFileName -Type file -Force -Value $result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment