Running Jobs Pre Merge to branch

I currently am creating a pipeline for PR’s to run tests, and on merge to main run tests and push images to registry.

PR Build Jobs :

  • Build & Test

Main Merge Jobs :

  • Build & Test
  • Modify Codebase
  • Push images to registry

My assumption was that all jobs upon a merge would run before the code is merged to the main branch; this is important b/c one of the jobs I have modifies the code base. After that step, the code can be merged to the main branch in parellel to/after the images are getting pushed to a registry.

Is there a way to set this up ?

This would be extremely difficult to set up. Any change to the codebase would need to get pushed back onto the PR (or main), which would trigger another build. You would need to build in the logic to make sure you don’t push code or images if nothing has changed, otherwise you’d have an infinite loop of jobs.

You should instead try to set up your repository in a way such that the user can easily run the code modification locally, and then your CI system verifies that they actually ran it. This may be harder for your users to keep track of, but it will be much, much easier to reason about.

As for your assumption, it may help to think of jobs as running on a branch, not on an operation. When your “main merge job” runs, it will run with the code on the main branch, so the PR code will be merged in already. As far as I know, there is no way to intercept a merge to run CI in Circle.