don’t know how your analysis runs.
I had a similar requirement, needed the scanner context of an analysis and it’s only available after the CE background task has finished.
I simply put my rest call after the waitForQualityGate() in the Jenkins pipeline to be sure the analysis has finished.