Hi @pmessier ,
Inside the script of task listener, the variable task is available, which corresponds to the DelegateTask interface.
You could get the execution instance as below
task.execution
Your code should be
task.execution.setVariable(“test”, “foo”);
See below link
https://docs.camunda.org/manual/7.7/user-guide/process-engine/scripting/#use-scripts-as-task-listeners