Smooth exit at flow based on the result of flow, continue to next flow or smooth exit in between

I have a job, flow1->flow2->flow3. Now based on the result of flow 2, I need to exit at flow 2 ( without fail, or not exit 1 or more). it should be successful completion of flow2 and should be an exit.
keeping “circleci-agent step halt” is not helping to stop in “flow2”

Hello

This is building upon the previous post here .

You will need to set a personal API token called CCI_TOKEN using the guide here.

Below is an example config that works from my testing the way it works is that there is a job polling an API to check for running jobs and once it finds there are no longer any running jobs it then starts the final job. This does look odd when looing at the workflow but it will work and the job will always run even if every job fails.

version: 2.1

jobs:
  upstream-job:
    docker: 
      - image: cimg/node:current
    steps:
      - run: echo "Hello I am '$CIRCLE_JOB', the upstream job"
      - run: sleep 10

  required-job:
    docker: 
      - image: cimg/node:current
    steps:
      - run: echo "Hello I am '$CIRCLE_JOB', a required job"
      - run: sleep 10

  other-required-job:
    docker: 
      - image: cimg/node:current
    steps:
      - run: echo "Hello I am '$CIRCLE_JOB', another required job"
      - run: sleep 10

  dependent-job:
    docker: 
      - image: circleci/node:current
    steps:
      - run: echo "Hello I am '$CIRCLE_JOB', the dependent job"
      - run: sleep 10
      
  waiter:
    docker: 
      - image: cimg/node:current
    steps:
      - run: |
          while [[ $(curl --location --request GET "https://circleci.com/api/v2/workflow/$CIRCLE_WORKFLOW_ID/job" --header "Circle-Token: $CCI_TOKEN"| jq -r '.items[]|select(.name != "waiter")|.status' | grep -c "running") -gt 0 ]]
            do
              sleep 5
            done
      - run: echo "All required jobs have now completed"

workflows:
  my-workflow:
    jobs:
      - upstream-job
      - required-job:
          requires:
            - upstream-job
      - other-required-job:
          requires:
            - upstream-job
      - waiter
      - dependent-job:
          requires:
            - waiter

Kind Regards
Owen Oliver