How to get all variables from BPMN process?

How to get all the process variables from a BPMN, given the processInstanceId or the BussinessKey? When I start BPMN I am setting the processVariable like below:

ProcessInstance processInstance = processEngine.getRuntimeService()
.startProcessInstanceByKey(CAMUNDA_CASE_MANAGEMENT_BPMN_ID,
caseData.getReferenceNumber(),
camundaCaseDataAccessor.getProcessVariable(caseData));

What have you tried so far?
In what context are your trying to retrieve them?

This worked. However, The same thing is not working in CMMN task

Map<String, Object> variables = processEngine.getRuntimeService()
.getVariables(processInstanceId);

For CMMN, I got the variables like below. I am looking for one common way to get these process variables irrespective of CMMN or BPMN task (activity)

Map<String, Object> variables = delegateTask.getProcessEngine().getCaseService()
.getVariables(delegateTask.getCaseInstanceId());