Checking simultaneously against gradle enterprise the timing lines up. The scan isn’t uploaded until the URL message printed which is after the callback is called now. (You can see this in the order of outputs above)
Is this a bug or is there some new logic needed to execute a callback after the upload?
The callback is called as soon as the URL is available, this is before the the build scan data has been uploaded. This has been the case for a while (plugin 3.3+, Gradle Enterprise 2020.2+). By default, build scans are uploaded in the background after the build has finished. However, disabling background uploading will not guarantee that the callback (buildScanPublished) is executed before the build scan is available for consumption.
Since I don’t know exactly what you need to do with the URL on your preflight server it’s hard to provide guidance to make it work, however, if you want to compute a score for build scans you might change your implementation, and instead of using the buildScanPublished hook, you could leverage the Gradle Enterprise API.
What version of plugin and Gradle were you using before and what are the new versions you are using now?
Thanks for the info. That confirms the behavior I saw. We’re using the 3.5 plugin currently with gradle 7. It wouldn’t surprise me if it was earlier than 3.3 with the 5.6.4 version.
I also already fiddled with background uploads to no effect.
How would the gradle enterprise API help in this case? Does it provide more ways to plug into the life cycle? What I’ve done for now is just save the scan ID during one phase of CI and use it later on which bysteps the issue.
Gradle Enterprise API does not provide any way to plug into the lifecycle so you would still need to either poll the API for builds or do the same thing, save the scan ID and use it later. Since I don’t know exactly what you need to compute all I can say is that Gradle Enterprise API might provide the data you need already computed or in a more easily accessible format. Here is an example on computing the cache hit percentage and avoidance savings ratio.
If your existing usage can be replaced with the easier-to-use Gradle Enterprise API, please consider migrating. Documentation is available here and the API reference here.