azure-devopsmarkdownazure-devops-wiki

Azure Release Notes Wiki Markdown date


I am completely new to this so any help and explanation would be appreciated. I have a created a template that will generate my release notes in our wiki. I am using the Generate Release Notes Markdown (crossplatform) extension by Richard Fennell. In the template section of the extension, I use this short and simple template:

# {{releaseDetails.name}}
**Date** : {{releaseDetails.modifiedOn}}
**Build Number**: {{buildDetails.buildNumber}}
{{#forEach workItems}}
{{#if isFirst}}## Work Items{{/if}}
- **{{lookup this.fields 'System.WorkItemType'}}** #{{this.id}}
{{/forEach}}

The output is as follows: Release-17 Date : Mon Dec 05 2022 18:19:37 GMT+0000 (Coordinated Universal Time) Build Number: 20221026.4

Everything is good except I would like to change the date and time format to just show Mon 12/05/2022 12:19 PM. That's it. I don't want the military time or the GMT +0000 stuff in there. EX: Release-17 Date : Mon 12/05/2022 12:19:37 PM Build Number: 20221026.4

Does anyone know how to format the date properly? Any help is appreciated. Thanks!

Searched forums and have not been able to find any solutions.


Solution

  • To modify the time zone and date format in Generate Release Notes Markdown, you need to add custom Javascript extenstion module in the Generate Release Notes Markdown task -> Custom Handlebars Extension.

    Here is an example:

    Javascript module

      module.exports = {date_formatter(theDate) {
         
             return theDate.toLocaleString("location");
         }};
    

    Task sample:

    - task: XplatGenerateReleaseNotes@3
      displayName: 'Generate Release Notes based on Release Comparison API'
      inputs:
        outputfile: '$(System.DefaultWorkingDirectory)/releasenotes.md'
        templateLocation: InLine
        inlinetemplate: |
         # {{releaseDetails.name}}
         **Date** : {{date_formatter releaseDetails.modifiedOn }}
         **Build Number**: {{buildDetails.buildNumber}}
         {{#forEach workItems}}
         {{#if isFirst}}## Work Items{{/if}}
         - **{{lookup this.fields 'System.WorkItemType'}}** #{{this.id}}
         {{/forEach}}
        replaceFile: true
        customHandlebarsExtensionCode: |
         module.exports = {date_formatter(theDate) {
         
             return theDate.toLocaleString("location");
         }};
    

    Refer to this sample: date_formatter.js and Handlebar Extensions