How to get labelNames from ResultsSummary in task execution?


#1

Hello everybody, I’m trying to implement my first bamboo plugin to be able to download an artifact based on a specific Plan and a label instead of the latest successfull artifact. The problem I have now is that when I’m trying to retrieve all label names in the task execution with this code:

for (ResultsSummary resultSummary: resultsSummaryMgr.getResultSummaries(new ResultsSummaryCriteria(planUsed.getKey(), BuildState.SUCCESS)))
                {    
                    for (String labelName: resultSummary.getLabelNames())
                    {                
                        buildLogger.addBuildLogEntry("Looking for label " + labelName);
                      
                        if (labelName.equals(configText))
                        {
                            choosenResult = resultSummary;           
                            break;
                        }                     
                    }              
                }

I got this error:

org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.atlassian.bamboo.resultsummary.AbstractResultsSummary.labellings, could not initialize proxy - no Session

Also If I’m running fairly the same code for the validation of the label in task configuration:

 for (ResultsSummary resultSummary: resultsSummaryMgr.getResultSummaries(new ResultsSummaryCriteria(planUsed.getKey(), BuildState.SUCCESS)))
                    {
                        for (String labelName: resultSummary.getLabelNames())
                        {                       
                            if (labelName.equals(labelToDownload))
                            {
                                valid = true;
                                
                                break;
                            }                     
                        }              
                    }

I don’t get this error.

The only way I found in task execution is to retrieve ResultsSummary is with the function getLatestResultsSummary() but this is not what I want.

Thanks for any help.


#2

Hi @epalardy,

I have not encountered your exact problem, but ran into similar ones occasionally. You might want to try wrapping your code in an explicit transaction using SAL’s transaction template - see Brydie’s answer to a similar issue for details.

Cheers,
Henrik


#3

Thank you very much this is exactly what I needed.