rfennell / AzurePipelines

A single Repo to contain the source for ALL my Azure DevOps Build/Release Extensions. The packages can be found in the Azure DevOps Marketplace
https://marketplace.visualstudio.com/search?term=fenn&target=VSTS&sortBy=Relevance
MIT License
343 stars 431 forks source link

[error]Error Processing handlebars [TypeError: Cannot read properties of undefined (reading 'length')] #1832

Closed SBhavana8 closed 7 months ago

SBhavana8 commented 7 months ago

Azure DevOps Extensions

Generate Release Notes (Node Cross Platform)

Platform

Azure DevOps Services

Azure DevOps Server (TFS) Version

No response

Extension Version

4.16.13(latest)

Describe the bug

Hi @rfennell

I am facing same issue as "Error Processing handlebars [TypeError: Cannot read properties of undefined (reading 'length')]"

Below is the error screeshot: image

Below attached file contains handlebars template:

handlebars.zip

Below attached file contains pipeline logs:

pipeline_logs.zip

Could you please help us and do the needful. Thanks in advance.

Repo Steps

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error ...

Expected Behavior

No response

Logging Information

No response

rfennell commented 7 months ago

Can I confirm was this working prior to the recent up or is it a new install or templates?

Looking at your template you only check the length for the array of PRs and WIs, and the log shows you have populated arrays for each of these.

Can you send me the dumped payload.json file so I can run it through my test harness

SBhavana8 commented 7 months ago
  1. Can I confirm was this working prior to the recent up or is it a new install or templates?

Ans : This was working prior in the other Azuredevops organisation and doesn't see any issues till date which is running successfully. Also I have used the entire handlebar template , PFA attachment for the handlebar template . We have added the ReleaseNotes extension recently to other Azuredevops organisation as well and tried with the same template but unfortunately its not working in our new organisation.

  1. Looking at your template you only check the length for the array of PRs and WIs, and the log shows you have populated arrays for each of these.

Ans : Instead of using entire handlebar i have used the simple template with the customisation.

  1. Can you send me the dumped payload.json file so I can run it through my test harness

Ans : I am not having privilege and approval to download the payload.json file from the machine i use to access the azuredevops. We are accessible to Azuredevops through Citrix only.

Below is the handlebar template for generating release note:

- task: XplatGenerateReleaseNotes@4
      displayName: 'Generate Release Notes'
      condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/dev-v7.0'))
      inputs:
        outputfile: '$(System.DefaultWorkingDirectory)inline.md'
        outputVariableName: 'OutputText'
        templateLocation: 'InLine'
        inlinetemplate: |

          # Notes for build  **{{buildDetails.buildNumber}}**
          |||
          |-|-|
          | **{{buildDetails.definition.name}}**|  **{{buildDetails.buildNumber}}**|
          | **Date**| {{buildDetails.startTime}}|
          | **Branch**| {{buildDetails.sourceBranch}}|
          | **BuildDate.Attempt**| {{buildDetails.buildNumber}}|
          | **Tags**| {{buildDetails.tags}}|
          | **Completed**| {{buildDetails.finishTime}}|
          | **Previous Build**| {{compareBuildDetails.buildNumber}}|
          | **Build Number**| {{buildDetails.id}}|
          | **Build Trigger PR Number**| {{lookup buildDetails.triggerInfo 'pr.number'}}|

          # Included Packages
          {{#forEach consumedArtifacts}}
          ## {{this.versionName}} ({{this.artifactCategory}})
          ### Commits
          | SHA | Message |
          |-|-|
          {{#forEach this.commits}}
          | {{truncate this.id 7}} | {{ this.message}} |
          {{/forEach}}

          ### Work Items
          | ID | Message |
          |-|-|
          {{#forEach this.workitems}}
          | {{this.id}} | {{lookup this.fields 'System.Title'}}  |
          {{/forEach}}

          {{/forEach}}
          ## Associated Pull Requests from previous build ({{pullRequests.length}})
          {{#forEach pullRequests}}
          * **[{{this.pullRequestId}}]({{replace (replace this.url "_apis/git/repositories" "_git") "pullRequests" "pullRequest"}})** {{this.title}}
          * Created by {{this.createdBy.displayName}}  {{thos.creationDate}}
          * Reviewed by:
          {{#forEach this.reviewers}}
            * {{this.displayName}}
          {{/forEach}}

          * Associated Commits (this includes commits on the PR source branch not associated directly with the build)
          {{#forEach this.associatedCommits}}
              - [{{truncate this.commitId 7}}]({{this.remoteUrl}}) - {{get_only_message_firstline this.comment}}
              {{#with (lookup_a_pullrequest_by_merge_commit ../../inDirectlyAssociatedPullRequests  this.commitId)}}
                - Associated PR {{this.pullRequestId}} - {{this.title}}
              {{/with}}
          {{/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'}}
            - **Assigned** {{#with (lookup this.fields 'System.AssignedTo')}} {{displayName}} {{/with}}
          {{/forEach}}

        #checkStage: true
        overrideStageName: 'false'
        stopOnRedeploy: true
        sortCS: true
        sortWi: true
        showOnlyPrimary: true
        dumpPayloadToConsole: true
        dumpPayloadToFile: true
        replaceFile: false
        appendToFile: true
        getParentsAndChildren: true
        getAllParents: true
        #overrideActiveBuildReleaseId: '$(Build.BuildId)'
        #overrideBuildReleaseId: '52857'
        getIndirectPullRequests: true
        stopOnError: true
        considerPartiallySuccessfulReleases: true
        checkForManuallyLinkedWI: true
        wiqlFromTarget: 'WorkItemLinks'

I am using above handlebar template in both of the orgs currently. Working fine with the earlier org. For the new org where I have installed the extension recently, I am facing the issue.

rfennell commented 7 months ago

If you can't pass me the payload.json, which is not an uncommon, I think the best approach is as follow

The best way to do this is use the test console which allows you to rerun the task from your dev PC as if rerunning for a specific build or release.

Can you use this to isolate the problem line?

SBhavana8 commented 7 months ago

Hi @rfennell

The issue was resolved by modifying the handlebars template.

Thanks for your help.

rfennell commented 7 months ago

Great glad you are unblocked