How to get the vcs revision for last successful job run

Background: We have a mono repo with several modules and a custom logic to figure out, if a job for a certain module has to be re-run. We are currently doing this by externally persisting information about the last ci runs (build_nr per job_name) and querying the circleci v1.1. API to check if the build was successful and if so the get the vcs revision. With that, we can check if a certain module was changed between the two commits

We are migrating to API v2 and i am asking myself, if it is possible with the new API to get rid of the external store. I am almost there, just a small piece is missing:

  • /insights/<project_slug>/workflows/<workflow_name>/jobs/<job_name>?branch=<branch_name> returns the job-ids and status of the resent runs for a given job name.
  • /project/<project_slug>/job/<job_nr> is returning the pipeline-id for a given job number
  • /pipeline/<pipeline-id> is returning the vcs_revision for a given pipeline id

But the /insights/.../jobs/... request is returning the job uuid not the job number, is there a way to get the job number by job uuid ? Is the job number the same as the build number ?

Or maybe there is a better/different way to get the vcs revision for the last successful job by job name ?

I just got feedback from support and want to share it with the community.

Since the ultimate goal within our monorepo setup and current solution is to only execute workflows that refer to specific changed modules, as opposed to all workflows in the monorepo, this is a perfect use case for the Dynamic Config feature discussed here - https://circleci.com/docs/2.0/dynamic-config/ - and this solution uses the continuation and path filtering orbs.

This approach is much better suited than bending the CircleCi API.