Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

How to get "the last build from yesterday"? #4255

OnQuickBuild ·

Hello Quickbuild support

I'm trying to use Groovy script to retrieve a specific build in history, to access the variables of that build.

And I don't see an easy method from "configuration" object to do this, so I use configuration.getBuilds()
and then try to identify the build I want. However, to access the collection of builds, it gives me this error

org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.pmease.quickbuild.model.Configuration.builds, could not initialize proxy - no Session
    at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:576)
    at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:215)
    at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:555)
    at org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:143)
    at org.hibernate.collection.internal.PersistentBag.iterator(PersistentBag.java:294)
    at sun.reflect.GeneratedMethodAccessor28156.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at...

My groovy code is just a few lines right now:

groovy:
def all_builds = configuration.getBuilds() as List
all_builds.each(){
  logger.warn(it.getVersion())
}

Could you help me? Thank you very much

  • solved #2
  • replies 3
  • views 3321
  • stars 0
Laba42 ·

You have to run this in a session on server node.

groovy:
import com.pmease.quickbuild.persistence.*
import com.pmease.quickbuild.Context; 

SessionManager.openSession()
try
{
   def startConfiguration  = system.configurationManager.get("root/path2configuration/thatYouWant/")
   for (build in startConfiguration.getBuilds() )
   {
        varValue  = build.getVarValue("YourVarName")      
        Context.logger.info("Value of the variable YourVarName of build ( " +  build.getId() + " )\t" + varValue  ) 
   }
}
finally
{
   SessionManager.closeSession(); 
}
OnQuickBuild ·

Thank you very much!
The session did the trick. Could you tell me why session is needed here?

robinshen ADMIN ·

QB uses the "Open Session In View" pattern to pull data from database as necessary. This pattern requires that operations pulling additional data from database should be using same database session. Hence open session here. Also please note that OSIV only works on server. If you want to run the script on agent side, instead of using "configuration.getBuilds()", please use "system.buildManager.getBuilds(configuration)".