How can TeamCity generate Release notes from JIRA during a build

How can TeamCity generate Release notes from JIRA during a build


I want TeamCity to generate release note list during the builds. I am using JIRA to store my user stories.  


I am going to create a PowerShell script that will query all my closed items (using JQL), then store that list in my DB (via POST API)

1) Create a power PowerShell script that will:
        a) Call a search JIRA API to query my items using JQL
        b) Post the results to my Web API.
2) Create a local API that will take a post request that contain a list of items
3) Call your PowerShell script from your JIRA and pass to it your parameters 

STEP 1.A & 1.B:

Create a PowerShell script that will take few parameters:
  • User name
  • password
  • domain 
  • Your Web API  Server name

You can modify this script to add more parameters if you want.
Here is how you will call your PowerShell script (for testing)

PowerShell.exe  -File "C:\GetReleasNotes.ps1" USER_NAME PWD DOMAIN_NAME SERVER_NAME

Here is the body of your PowerShell script:

$url = "https://JIRASERVER:8443/rest/api/2/search?jql=project%20%3D%20PROJECTNAME%20AND%20status%20%3D%20Closed%20AND%20Sprint%20in%20openSprints()&fields=key,summary" 

$username = $args[0];
$password = $args[1];
$domain = $args[2];
$server = $args[3];

$webRequest = [System.Net.WebRequest]::Create($url);
$creds = New-Object System.Net.NetworkCredential -ArgumentList $username, $password;
$webRequest.Credentials = $creds

$webRequest.PreAuthenticate = $true
$webRequest.Headers.Add("AUTHORIZATION", "Basic");
[System.Net.WebResponse] $resp = $webRequest.GetResponse();
$rs = $resp.GetResponseStream();
[System.IO.StreamReader] $sr = New-Object System.IO.StreamReader -argumentList $rs;
[string] $results = $sr.ReadToEnd()  

<# Post the results to your Web.API#>
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }
$url = "http://${server}/WEB.API/api/ReleasNotes"; #You Need to create this in step (2)

$PWord = ConvertTo-SecureString –String $password  –AsPlainText -Force;
$cred = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList $domain\$username,$PWord ;
$releaseNotes = ConvertTo-Json $results;
$body = @{
    releaseNotes = $releaseNotes
Invoke-RestMethod -Method Post -Uri $url -Credential $cred -Body $body;


I am using ASP web API so my example is for that. I am not going to put the exact code but I will give you and idea of how your API should look like

public string Post([FromBody] JToken releaseNotes)
            if (String.IsNullOrEmpty(releaseNotes.ToString())) return "FAIL: The request body does not contain any data!";
            string jRequestBody = Regex.Unescape(releaseNotes.First.First.Value<string>());
            jRequestBody = jRequestBody.Trim().Remove(0, 1);
            jRequestBody = jRequestBody.Remove(jRequestBody.LastIndexOf("\""), 1);
                    JArray jReleaseNotes = JArray.Parse(String.Format("[{0}]", jRequestBody));
                    //Delete all the old data ... you need to add that code

                    //NOTE: I have a EF class maned ReleaseNoteItem (implementing IChangeTracker)
                    //That I will populate here
                    foreach (ReleaseNoteItem ren in jReleaseNotes.First["issues"].Select(issue => new ReleaseNoteItem
                        RenNumber = issue["key"].Value<string>(),
                        Summary = issue["fields"]["summary"].Value<string>()
                      // you will need to add it to you EF Object 
            catch (Exception ex)
                Logging.LogException(ex, "[API]  Release Notes Post");
            return jRequestBody;


Add a build step in TeamCity to execute the PowerShell script like so.


Popular posts from this blog

DataTables server-side processing example feeding from SharePoint 2010 search service plus Reformatting Columns To Hyperlink