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 430 forks source link

Always getting the workitems as empty array in the build pipe line #917

Closed rajeswar-net closed 3 years ago

rajeswar-net commented 3 years ago

Describe the bug The task always showing the empty array of work itmes, pull requests and builds. Tried all the following, and those are either empty array or no result.

Associated work items

{{json this.workitems}}

associatedWorkitems

{{json this.associatedWorkitems}}

Associated pull requests

{{json this.pullRequests}}

Associated relations

{{json this.relations}}

Global work items

{{json workitems}}

Global pull requests

{{json pullRequests}}

builds

{{json this.builds}}

tests

{{json this.tests}}

inDirectlyAssociatedPullRequests

{{json this.inDirectlyAssociatedPullRequests}}

commits

{{json this.commits}}

compareBuildDetails

{{json this.compareBuildDetails}}

currentStage

{{json this.currentStage}}

Remember that there are a number of Azure DevOps (VSTS) extensions in this repo so please say which one you are using, and if an extension contains multiple tasks which task also

To Reproduce Steps to reproduce the behavior:

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

Expected behavior A clear and concise description of what you expected to happen.

Screenshots image

Logs 2021-01-04T15:15:03.4418165Z ##[debug]Evaluating condition for step: 'Generate Release Notes based on Release Comparison API' 2021-01-04T15:15:03.4420242Z ##[debug]Evaluating: succeeded() 2021-01-04T15:15:03.4420802Z ##[debug]Evaluating succeeded: 2021-01-04T15:15:03.4422114Z ##[debug]=> True 2021-01-04T15:15:03.4422652Z ##[debug]Result: True 2021-01-04T15:15:03.4423261Z ##[section]Starting: Generate Release Notes based on Release Comparison API 2021-01-04T15:15:03.4609634Z ============================================================================== 2021-01-04T15:15:03.4609996Z Task : Generate Release Notes (Crossplatform) 2021-01-04T15:15:03.4610402Z Description : Generates a release notes file in a format of your choice from the build or release history 2021-01-04T15:15:03.4610725Z Version : 3.39.2 2021-01-04T15:15:03.4610937Z Author : Black Marble 2021-01-04T15:15:03.4611413Z Help : Version: 3.39.2. More Information 2021-01-04T15:15:03.4612102Z ============================================================================== 2021-01-04T15:15:03.5091095Z ##[debug]Using node path: C:\agents\2.179.0\externals\node10\bin\node.exe 2021-01-04T15:15:03.9944965Z ##[debug]agent.TempDirectory=D:\a_temp 2021-01-04T15:15:03.9967773Z ##[debug]loading inputs and endpoints 2021-01-04T15:15:03.9990763Z ##[debug]loading ENDPOINT_AUTH_PARAMETER_SYSTEMVSSCONNECTION_ACCESSTOKEN 2021-01-04T15:15:04.0033149Z ##[debug]loading ENDPOINT_AUTH_SCHEME_SYSTEMVSSCONNECTION 2021-01-04T15:15:04.0038105Z ##[debug]loading ENDPOINT_AUTH_SYSTEMVSSCONNECTION 2021-01-04T15:15:04.0038887Z ##[debug]loading INPUT_APPENDTOFILE 2021-01-04T15:15:04.0039557Z ##[debug]loading INPUT_CHECKSTAGE 2021-01-04T15:15:04.0040260Z ##[debug]loading INPUT_CUSTOMHANDLEBARSEXTENSIONFILE 2021-01-04T15:15:04.0040950Z ##[debug]loading INPUT_DUMPPAYLOADFILENAME 2021-01-04T15:15:04.0041716Z ##[debug]loading INPUT_DUMPPAYLOADTOCONSOLE 2021-01-04T15:15:04.0043055Z ##[debug]loading INPUT_DUMPPAYLOADTOFILE 2021-01-04T15:15:04.0043520Z ##[debug]loading INPUT_GETALLPARENTS 2021-01-04T15:15:04.0043997Z ##[debug]loading INPUT_GETINDIRECTPULLREQUESTS 2021-01-04T15:15:04.0044523Z ##[debug]loading INPUT_GETPARENTSANDCHILDREN 2021-01-04T15:15:04.0044990Z ##[debug]loading INPUT_MAXRETRIES 2021-01-04T15:15:04.0045438Z ##[debug]loading INPUT_OUTPUTFILE 2021-01-04T15:15:04.0045873Z ##[debug]loading INPUT_PAUSETIME 2021-01-04T15:15:04.0046340Z ##[debug]loading INPUT_REPLACEFILE 2021-01-04T15:15:04.0046811Z ##[debug]loading INPUT_SEARCHCROSSPROJECTFORPRS 2021-01-04T15:15:04.0048523Z ##[debug]loading INPUT_SHOWONLYPRIMARY 2021-01-04T15:15:04.0050395Z ##[debug]loading INPUT_SORTWI 2021-01-04T15:15:04.0052364Z ##[debug]loading INPUT_STOPONREDEPLOY 2021-01-04T15:15:04.0054477Z ##[debug]loading INPUT_TEMPLATEFILE 2021-01-04T15:15:04.0056371Z ##[debug]loading INPUT_TEMPLATELOCATION 2021-01-04T15:15:04.0064597Z ##[debug]loaded 22 2021-01-04T15:15:04.0069666Z ##[debug]Agent.ProxyUrl=undefined 2021-01-04T15:15:04.0071064Z ##[debug]Agent.CAInfo=undefined 2021-01-04T15:15:04.0071468Z ##[debug]Agent.ClientCert=undefined 2021-01-04T15:15:04.0072224Z ##[debug]Agent.SkipCertValidation=undefined 2021-01-04T15:15:04.1770719Z ##[debug]Starting Tag XplatGenerateReleaseNotes task 2021-01-04T15:15:04.1771598Z ##[debug]System.TeamFoundationCollectionUri=https://dev.azure.com/xxxx/ 2021-01-04T15:15:04.1772172Z ##[debug]System.TeamProject=ResearchDevelopment 2021-01-04T15:15:04.1780349Z ##[debug]templateLocation=File 2021-01-04T15:15:04.1782090Z ##[debug]templatefile=D:\a\1\s\NewBuildTemplate.md 2021-01-04T15:15:04.1782477Z ##[debug]inlinetemplate=undefined 2021-01-04T15:15:04.1783580Z ##[debug]outputfile=D:\a\1\a\newbuildreleasenotes.md 2021-01-04T15:15:04.1784002Z ##[debug]outputVariableName=undefined 2021-01-04T15:15:04.1785240Z ##[debug]showOnlyPrimary=false 2021-01-04T15:15:04.1786346Z ##[debug]replaceFile=True 2021-01-04T15:15:04.1787431Z ##[debug]appendToFile=True 2021-01-04T15:15:04.1789348Z ##[debug]getParentsAndChildren=false 2021-01-04T15:15:04.1789919Z ##[debug]searchCrossProjectForPRs=False 2021-01-04T15:15:04.1790433Z ##[debug]overrideStageName=undefined 2021-01-04T15:15:04.1790928Z ##[debug]stopOnRedeploy=False 2021-01-04T15:15:04.1791580Z ##[debug]SortWi=false 2021-01-04T15:15:04.1792097Z ##[debug]customHandlebarsExtensionCode=undefined 2021-01-04T15:15:04.1792848Z ##[debug]customHandlebarsExtensionFile=customHandlebarsExtension 2021-01-04T15:15:04.1793459Z ##[debug]customHandlebarsExtensionFolder=undefined 2021-01-04T15:15:04.1794091Z ##[debug]gitHubPat=undefined 2021-01-04T15:15:04.1794572Z ##[debug]bitbucketSecret=undefined 2021-01-04T15:15:04.1795065Z ##[debug]bitbucketUser=undefined 2021-01-04T15:15:04.1795568Z ##[debug]dumpPayloadToFile=true 2021-01-04T15:15:04.1796061Z ##[debug]dumpPayloadToConsole=true 2021-01-04T15:15:04.1796612Z ##[debug]dumpPayloadFileName=D:\a\1\a/payload.json 2021-01-04T15:15:04.1797212Z ##[debug]checkStage=true 2021-01-04T15:15:04.1798263Z ##[debug]getAllParents=false 2021-01-04T15:15:04.1798749Z ##[debug]tags=undefined 2021-01-04T15:15:04.1799224Z ##[debug]overridePat=undefined 2021-01-04T15:15:04.1799708Z ##[debug]overrideBuildReleaseId=undefined 2021-01-04T15:15:04.1800238Z ##[debug]getIndirectPullRequests=true 2021-01-04T15:15:04.1800735Z ##[debug]maxRetries=20 2021-01-04T15:15:04.2138574Z ##[debug]Build.BuildId=2581 2021-01-04T15:15:04.2139144Z ##[debug]Release.ReleaseId=undefined 2021-01-04T15:15:04.2139628Z ##[debug]Release.DefinitionId=undefined 2021-01-04T15:15:04.2140271Z ##[debug]Release_EnvironmentName=undefined 2021-01-04T15:15:04.2140976Z ##[debug]ReleaseNotes.Fix349=undefined 2021-01-04T15:15:04.2182309Z Creating Azure DevOps API connections for https://dev.azure.com/xxxxx/ with 'allowRetries' set to 'true' and 'maxRetries' count to '20' 2021-01-04T15:15:04.2185046Z ##[debug]Getting System.AccessToken 2021-01-04T15:15:04.2185718Z ##[debug]Getting credentials the agent is running as 2021-01-04T15:15:04.2190195Z ##[debug]SYSTEMVSSCONNECTION exists true 2021-01-04T15:15:04.2190703Z ##[debug]Found an OAUTH token 2021-01-04T15:15:04.2191204Z Creating the credential handler from the OAUTH token 2021-01-04T15:15:04.6054588Z Getting the current build details 2021-01-04T15:15:04.6584468Z ##[debug]System.StageName=default 2021-01-04T15:15:04.6585621Z Getting items associated the builds since the last successful build to the stage 'default' 2021-01-04T15:15:04.8613221Z Found '27' matching builds to consider 2021-01-04T15:15:04.8613471Z Comparing 2581 against 2581 2021-01-04T15:15:04.8613672Z Ignore compare against self 2021-01-04T15:15:04.8613842Z Comparing 2580 against 2581 2021-01-04T15:15:04.8613996Z Considering build 2021-01-04T15:15:04.9408015Z Found required stage __default in the completed and successful state in build 2580 2021-01-04T15:15:04.9408439Z Getting the details between 2580 and 2581 2021-01-04T15:15:04.9651233Z Using workaround for build API limitation (see issue #349) 2021-01-04T15:15:04.9888260Z ##[debug]ReleaseNotes.Fix349.MaxCommits=undefined 2021-01-04T15:15:04.9889064Z ##[debug]ReleaseNotes.Fix349.MaxWorkItems=undefined 2021-01-04T15:15:05.0292096Z Processing commits found 2021-01-04T15:15:05.0926053Z ##[debug]Found 0 test results associated with the build 2021-01-04T15:15:05.0926749Z ##[debug]No tests associated with build 2581 2021-01-04T15:15:05.0927122Z Get the file details associated with the commits 2021-01-04T15:15:05.0933106Z Get any test details associated with the build 2021-01-04T15:15:05.1568910Z ##[debug]Found 0 test results associated with the build 2021-01-04T15:15:05.1569638Z ##[debug]No tests associated with build 2581 2021-01-04T15:15:05.1570009Z Removing duplicate Commits from master list 2021-01-04T15:15:05.1570406Z Removing duplicate WorkItems from master list 2021-01-04T15:15:05.1576510Z Expanding the truncated commit messages... 2021-01-04T15:15:05.1576848Z Expanded truncated commit messages 0 2021-01-04T15:15:05.1583112Z Get details of [0] WIs 2021-01-04T15:15:05.1584195Z Leaving WI in default order as returned by API 2021-01-04T15:15:05.1584954Z ##[debug]Getting the details of build 2581 from default project 2021-01-04T15:15:05.1859631Z The default artifact for the release was not linked to an Azure DevOps Git Repo Pull Request 2021-01-04T15:15:05.1861028Z Getting all completed Azure DevOps Git Repo PRs in the Team Project ResearchDevelopment 2021-01-04T15:15:05.1865938Z ##[debug]Get batch of PRs [0] - [1000] 2021-01-04T15:15:05.3361922Z ##[debug]Adding batch of 127 PRs 2021-01-04T15:15:05.3362300Z Found 127 Azure DevOps PRs in the repo 2021-01-04T15:15:05.3362537Z Enriching known Pull Requests 2021-01-04T15:15:05.3365957Z Checking the CS associated with the PRs to see if they are inturn associated PRs 2021-01-04T15:15:05.3370907Z Total Builds: [0] 2021-01-04T15:15:05.3371387Z Total Commits: [0] 2021-01-04T15:15:05.3371879Z Total Workitems: [0] 2021-01-04T15:15:05.3374146Z Total Related Workitems (Parent/Children): [0] 2021-01-04T15:15:05.3374806Z Total Release Tests: [0] 2021-01-04T15:15:05.3375094Z Total Tests: [0] 2021-01-04T15:15:05.3375352Z Total Pull Requests: [0] 2021-01-04T15:15:05.3375639Z Total Indirect Pull Requests: [0] 2021-01-04T15:15:05.3376045Z Start of payload data dump 2021-01-04T15:15:05.3476110Z End of payload data dump 2021-01-04T15:15:05.3476336Z Writing payload data to file D:\a\1\a/payload.json 2021-01-04T15:15:05.3476808Z ##[debug]Using template mode File 2021-01-04T15:15:05.3477112Z Loading template file D:\a\1\s\NewBuildTemplate.md 2021-01-04T15:15:05.3477461Z ##[debug]Loading handlebar template 2021-01-04T15:15:05.3477784Z ##[debug]Processing template 2021-01-04T15:15:05.3478095Z ##[debug] WI: 0 2021-01-04T15:15:05.3478383Z ##[debug] CS: 0 2021-01-04T15:15:05.3478722Z ##[debug] PR: 0 2021-01-04T15:15:05.3479010Z ##[debug] Builds: 0 2021-01-04T15:15:05.3479328Z ##[debug] Global Tests: 0 2021-01-04T15:15:05.3479679Z ##[debug] Release Tests: 0 2021-01-04T15:15:05.3480007Z ##[debug] Related WI: 0 2021-01-04T15:15:05.3480300Z ##[debug] Indirect PR: 0 2021-01-04T15:15:05.3480612Z ##[debug]Processing handlebar template 2021-01-04T15:15:05.3778500Z Loading handlebars-helpers extension 2021-01-04T15:15:05.6440337Z ##[debug]No custom Handlebars code to process 2021-01-04T15:15:05.7463017Z Completed processing template 2021-01-04T15:15:05.7463663Z Writing output file D:\a\1\a\newbuildreleasenotes.md 2021-01-04T15:15:05.7467735Z Finished writing output file D:\a\1\a\newbuildreleasenotes.md 2021-01-04T15:15:05.7470662Z ##[debug]task result: Succeeded 2021-01-04T15:15:05.7480830Z ##[debug]Processed: ##vso[task.complete result=Succeeded;] 2021-01-04T15:15:05.8015331Z ##[section]Finishing: Generate Release Notes based on Release Comparison API

What is the issue see:

rfennell commented 3 years ago

As the log shows the task has been unable to find any associated WI, commits or tests. Hence those blocks are empty in the generated release notes.

Remember the task compares builds, so in your log we can see Getting the details between 2580 and 2581, I assume that since 2580 there have been no commits etc.

rajeswar-net commented 3 years ago

@rfennell How can I get the global list of WI and Commits? Because in the older version we used to get all the Work Items using @@WILOOP@@, how can I do that here in the latest?

rfennell commented 3 years ago

The structure would be something along the lines of the sample shown below, as per the documentation

But remember these global list is just the WI/CS associated with the builds

{{#forEach this.workItems}}
{{#if isFirst}}### WorkItems {{/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}}
   - **Description** {{{lookup this.fields 'System.Description'}}}
{{/forEach}} 

{{#forEach commits}}
{{#if isFirst}}### Associated commits{{/if}}
* ** ID{{this.id}}** 
   -  **Message:** {{this.message}}
   -  **Commited by:** {{this.author.displayName}} 
   -  **FileCount:** {{this.changes.length}} 
{{/forEach}}
github-actions[bot] commented 3 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

kAleksei commented 1 year ago

Hello, faced with the same issue. Here is the log:

Getting items associated the builds since the last successful build to the stage 'Build'
Found '32' matching builds to consider
Matching 'successful' builds only 
Comparing 197168 against 197168
Ignore compare against self
Comparing 196532 against 197168
Considering build
Found required stage Build in the state 2 with the result 0 state for build 196532
Using the build 196532
Getting the details between 196532 and 197168
Using workaround for build API limitation (see issue #349)
Processing commits found
Cannot get extra commit and work item details of the 'Repository' artifact 'templates', so just adding base information
Get the file details associated with the commits
Get any test details associated with the build
Get any manual test run details associated with the build
Removing duplicate Commits from master list
Expanding the truncated commit messages...
Expanded truncated commit messages 0
Sorting CS by created date
Find any WorkItems linked from GitHub using the AB#123 format
Adding 0 found using AB#123 links in GitHub comments
Removing duplicate WorkItems from master list
Getting tests linked to WorkItems
Sorting WI by type then id
The default artifact for the release was not linked to an Azure DevOps Git Repo Pull Request
Getting all completed Azure DevOps Git Repo PRs in the Team Project Shared
Getting associated PRs
Found 30494 Azure DevOps PRs in the repo
Enriching known Pull Requests
Total Builds: [0]
Total Commits: [0]
Total Workitems: [0]
Total Related Workitems (Parent/Children): [0]
Total Release Tests: [0]
Total Tests: [560]
Total Manual Test Runs: [0]
Total Manual Test Configurations: [0]
Total Pull Requests: [0]
Total Indirect Pull Requests: [0]
Total Associated Test WI: [0]
Total Consumed Artifacts: [1]
Total WIQL Workitems: [0]

Talking about Comparing 196532 against 197168 the are a few builds, where 196532 is just the previous gate build from the test branch, before merging the PR (Gated Build). But the comparing should not be performed, since this is two unrelated builds.

rfennell commented 1 year ago

By default the comparison is done against the las successful build of the definition, irrespective of the branch, but there are technique you can do make sure the comparison is a build of a certain criteria

Watch the video of the conference session I did on this tool, as I think this might provide an answer.

What I do is put the release notes task in it's own stage that is only run if a certain condition is met e.g. a human approves release to that stage, or a condition is met that allows entry into the stage e.g. a parameter is not set to beta - or both.

Remember to also checkout the WIKI for the settings required to get this working

This model means that the task is only run when it is required, and will look back to the last successful build that ran the current stage so showing the changes since the last release to that stage.

kAleksei commented 1 year ago

Yes, we are running this task only while building on the master branch. But seems like the task is looking for last builds ignoring even if the task has run or not. Thank you for the link to the WIKI. Will check whether some settings can affect the result and come back to you.

pak-sergey commented 1 year ago

Hello, having same issue: Found 100 Azure DevOps PRs in the repo Checking for PRs associated with the commit 686cb387b21a7a0699ce81866423563025128877

image

And I have these in the template:

Associated Pull Requests ({{pullRequests.length}})

    {{#forEach pullRequests}}
    * **[{{this.pullRequestId}}]({{replace (replace this.url "_apis/git/repositories" "_git") "pullRequests" "pullRequest"}})** {{this.title}}
    * Associated Work Items
    {{#forEach this.associatedWorkitems}}
      {{#with (lookup_a_work_item ../../relatedWorkItems this.url)}}
        - [{{this.id}}]({{replace this.url "_apis/wit/workItems" "_workitems/edit"}}) - {{lookup this.fields 'System.Title'}}
      {{/with}}
    {{/forEach}}
    * Associated Commits (this includes commits on the PR source branch not associated directly with the build)
    {{#forEach this.associatedCommits}}
        - [{{this.commitId}}]({{this.remoteUrl}}) -  {{this.comment}}
    {{/forEach}}
    {{/forEach}}

    # Builds with associated WI/CS ({{builds.length}})
    {{#forEach builds}}
      {{#if isFirst}}## Builds {{/if}}
      ##  Build {{this.build.buildNumber}}

      {{#forEach this.workitems}}
        {{#if isFirst}}### Workitems {{/if}}
        - WI {{this.id}}
      {{/forEach}} 

      {{#forEach this.commits}}
        {{#if isFirst}}### Commits {{/if}}
        - CS {{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'}}
      - **Assigned** {{#with (lookup this.fields 'System.AssignedTo')}} {{displayName}} {{/with}}
      - **Description** {{{lookup this.fields 'System.Description'}}}
      - **PRs**
    {{/forEach}}

    ## List of WI returned by WIQL ({{queryWorkItems.length}})
    {{#forEach queryWorkItems}}
    *  **{{this.id}}** {{lookup this.fields 'System.Title'}}
    {{/forEach}}

And generated release:

Associated Pull Requests (1)

  #455 - Ajouter generation de release notes et wiki

Can't find what's wrong.