How to programmatically get the Spark Job ID of a running Spark Task?

FRG96
New Contributor III

In Spark we can get the Spark Application ID inside the Task programmatically using:

SparkEnv.get.blockManager.conf.getAppId

and we can get the Stage ID and Task Attempt ID of the running Task using:

TaskContext.get.stageId
TaskContext.get.taskAttemptId

Is there any way to get the Spark Job Id that is associated with a running Task (preferably using TaskContext or SparkEnv)?

Linked Question on StackOverflow: https://stackoverflow.com/questions/70929032/how-to-programmatically-get-the-spark-job-id-of-a-runni...