I’d like to run a collect job after a fan-out finish even if one of the jobs of the fan-out was a failure.
Any ideas?
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