Generate Releases Notes easily
Tags: azuredevops
Published: 2020-09-27 13:54:08

<sub><span>Photo by <a href="https://unsplash.com/@aaronburden">Aaron Burden</a> on <a href="https://unsplash.com/s/photos/writing?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></span></sub>

I came on this [post](https://blogs.blackmarble.co.uk/rfennell/2020/09/15/how-can-i-automatically-create-azure-devops-release-notes-and-how-can-i-publish-them/) about using 2 tasks to generate release notes on Azure DevOps, and just want to share it with you.


# Generate Notes in Build

You can easily add the task **Generate Release Notes (Crossplatform)** to your build and use the template suggested by the author, as inline template.


```yaml
# Notes for build 
**Build Number**: {{buildDetails.id}}
**Build Trigger PR Number**: {{lookup buildDetails.triggerInfo 'pr.number'}} 

# Associated Pull Requests ({{pullRequests.length}})
{{#forEach pullRequests}}
{{#if isFirst}}### Associated Pull Requests (only shown if  PR) {{/if}}
*  **PR {{this.id}}**  {{this.title}}
{{/forEach}}

# Builds with associated WI/CS ({{builds.length}})
{{#forEach builds}}
{{#if isFirst}}## Builds {{/if}}
##  Build {{this.build.buildNumber}}
{{#forEach this.commits}}
{{#if isFirst}}### Commits {{/if}}
- CS {{this.id}}
{{/forEach}}
{{#forEach this.workitems}}
{{#if isFirst}}### Workitems {{/if}}
- WI {{this.id}}
{{/forEach}} 
{{/forEach}}

# Global list of WI ({{workItems.length}})
{{#forEach workItems}}
{{#if isFirst}}## Associated Work Items (only shown if  WI) {{/if}}
*  **{{this.id}}**  {{lookup this.fields 'System.Title'}}
  - **WIT** {{lookup this.fields 'System.WorkItemType'}} 
  - **Tags** {{lookup this.fields 'System.Tags'}}
{{/forEach}}

{{#forEach commits}}
{{#if isFirst}}### Associated commits{{/if}}
* ** ID{{this.id}}** 
  -  **Message:** {{this.message}}
  -  **Commited by:** {{this.author.displayName}} 
  -  **FileCount:** {{this.changes.length}} 
{{#forEach this.changes}}
      -  **File path (TFVC or TfsGit):** {{this.item.path}}  
      -  **File filename (GitHub):** {{this.filename}}  
{{/forEach}}
{{/forEach}}
```

It will generate a file to **$(Build.ArtifactStagingDirectory)/releasenotes.md** and you can publish it using the Publish task.


# Generate Notes in Release

Like in the previous section, we can use the same tasks to generate the release notes.
But we want to aggregate it.

The task **Git based WIKI Single File Updater from Black Marble** is also available to update Azure DevOps Wiki with file. Let's use it !

We need to fill a lot of information.

## Wiki

- Wiki repository

Go to the Wiki. 
By clicking on the 3 dots in the Azure DevOps Wiki, you will be able to clone the Repository and get its url.

![Get the clone button](https://dev-to-uploads.s3.amazonaws.com/i/um0v2lckc8p2p7eul73k.png)

- Branch

Just use the default branch (master) and leave the branch empty.

- Page name

For the name of the page, you can leverage [predefined variables](https://docs.microsoft.com/en-us/azure/devops/pipelines/release/variables?view=azure-devops&tabs=batch#default-variables---release) in Azure DevOps to generate one different page each time.

For example : $(Release.DeploymentName)-$(Release.DeploymentID).md


## Git

Fill an explicit Git Name and Git Email as the will be written to track the update of your wiki.

## Azure DevOps credentials

I recommend to create a variable group to store your username and the Personal Access Token used for authentication. It will be easier for you to track and reuse them, if needed.

Go create a variable group, and add both username and Personal Authentication Token as secrets.

To generate the Personal Access Token:
- click on **User Settings**
- click on **Personal access tokens**
- click on New Token
- Grant only **Read & Write** authorization
- Copy the token in the secret variable


[Troubleshooting page](https://github.com/rfennell/AzurePipelines/wiki/WIKI-Updater-Tasks#troubleshooting) in case of issues.



Hope this helps !