ProcessInstance pi = runtimeService
.startProcessInstanceByKey("TestFixture70.testVariableMigration", params);
ExecutionQuery executionQuery = runtimeService.createExecutionQuery().processInstanceId(pi.getId());
JobQuery jobQuery = managementService.createJobQuery().processInstanceId(pi.getId());
TaskQuery taskQuery = taskService.createTaskQuery().processInstanceId(pi.getId());
Execution execution = executionQuery.singleResult();
Job job = jobQuery.singleResult();
// add a variable
runtimeService.setVariableLocal(execution.getId(), "aVariableName", "aVariableValue");
// execute available job
managementService.executeJob(job.getId());
// update execution reference
execution = executionQuery.singleResult();
// update variable
runtimeService.setVariableLocal(execution.getId(), "aVariableName", "newVariableValue");
// add another new variable
runtimeService.setVariableLocal(execution.getId(), "anotherVariableName", "anotherVariableValue");
// update job reference
job = jobQuery.singleResult();
// execute available job
managementService.executeJob(job.getId());
// get current task
Task task = taskQuery.singleResult();
// add a new task variable
taskService.setVariableLocal(task.getId(), "aLocalTaskVariableName", "aLocalTaskVariableValue");
// add "aVariableName" variable as local task variable