Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XplatGenerateReleaseNotes V3 selects wrong previous build #934

Closed
dasMulli opened this issue Jan 29, 2021 · 1 comment · Fixed by #935
Closed

XplatGenerateReleaseNotes V3 selects wrong previous build #934

dasMulli opened this issue Jan 29, 2021 · 1 comment · Fixed by #935

Comments

@dasMulli
Copy link
Contributor

Describe the bug
When running the XplatGenerateReleaseNotes V3 task it selects wrong previous builds for comparison.
Running in Azure DevOps (Service) multi-stage YAML pipelines, I tried to use the task to generate release notes by looking for previous builds that successfully deployed to a specific stage.

However it finds very old pipeline runs that happen to match the stage requirement.

Initial debbuging shows that buildApi.getBuilds(..) in getLastSuccessfulBuildByStage (ReleaseNotesFunctions.ts) returns the builds in an arbitrary order. The second entry is a build from July 2020 (so nearly half a year ago) that happens to match the requirement.

Experementing with the query order parameter of getBuilds() - e.g. passing BuildQueryOrder.QueueTimeDescending - seem to be futile as well - the returned order changes but is still mixed (part lexically on the build number (which we override from within the build to a SemVer2 version) and part ordered by time).

The most successful approach I ended up finding was to do a client side sort:

--- a/Extensions/XplatGenerateReleaseNotes/V3/ReleaseNotesFunctions.ts
+++ b/Extensions/XplatGenerateReleaseNotes/V3/ReleaseNotesFunctions.ts
@@ -797,12 +797,19 @@ export async function getLastSuccessfulBuildByStage(
             }
         }

+        builds.sort((a, b) => <any>b.queueTime - <any>a.queueTime);
+
+        let foundSelf = false;
+
         for (let buildIndex = 0; buildIndex < builds.length; buildIndex++) {
             const build = builds[buildIndex];
             agentApi.logInfo (`Comparing ${build.id} against ${buildId}`);
             // force the cast to string as was getting a type mimatch
             if (build.id.toString() === buildId.toString()) {
                 agentApi.logInfo("Ignore compare against self");
+                foundSelf = true;
+            } else if (!foundSelf) {
+                agentApi.logInfo("Ignore compare since not yet passed the current build");
             } else {
                 if (tags.length === 0 ||
                     (tags.length > 0 && build.tags.sort().join(",") === tags.sort().join(","))) {
@rfennell
Copy link
Owner

Seems a reasonable approach to guarantee the order. I will have a that the PR my test harness

That said the build.id should be a unique incrementing int, it s not the build.buildnumber which is the one you can overload wit SEMVER or whatever you use

Thanks for debugging this

This was referenced Nov 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants