you have to cast the processInstance to WorkflowProcessInstanceImpl:
use :
WorkflowProcessInstanceImpl processInstance = (WorkflowProcessInstanceImpl) ksession.getProcessInstance(processInstanceId)
or
WorkflowProcessInstanceImpl instance=(WorkflowProcessInstanceImpl) ksession.startProcess("org.jbpm.sample.hello",paras);
and processInstance.getVariable("ret");
this is working from me
HTH