How to get the chain stage for a particular build number in a plan


For the robot plugin that I am developing in-house, I need to fetch the jobs (through the chain (chain stages))
for a particular build number in a plan.
As some previous build of a plan may not have all the new jobs. But I can’t seem to find an API that gives me the Chain (com.atlassian.bamboo.chains.Chain) corresponding to a build number of a plan for fetching the jobs configured for that build.

My current implementation is like below

        listJobIds = new ArrayList<String>();
        listJobNames = new ArrayList<String>();

        PlanKey planKey = PlanKeys.getPlanKey(getPlanKey());
        Chain planChain = (Chain) planManager.getPlanByKey(planKey);

       for (ChainStage chainStage : planChain.getStages())
            for (Job job: chainStage.getJobs())
                Plan plan = planManager.getPlanByKey(job.getPlanKey());
                List<TaskDefinition> tasks = plan.getBuildDefinition().getTaskDefinitions();
                for(TaskDefinition task : tasks) {
                    if(task.getPluginKey().equals(RobotTaskType.KEY) && task.isEnabled()) {

But this gives me the list of jobIds and jobName in the plan latest configuration. How to get the job Ids/Name of some previous build number of a plan ?

@acalantog, @achystoprudov any idea ?