You overlooked:
For use from trusted code, such as global libraries, which can manipulate internal Jenkins APIs.
So put in a function marked as @NonCPS could work, I guess.
import org.jenkinsci.plugins.workflow.graph.FlowNode
@NonCPS
def getFlowID() {
def flow = getContext(FlowNode.class)
echo flow.id
}
node() {
stage("1") {
getFlowID()
sh "echo OK"
}
}