Running a Job/Step even if the build fails

Hi Everybody,
We need to do some cleanup even for failed builds. This is critical to release expensive cloud resources. Cannot find this in documentation. Is there a new/hacky way for this?

Forcing a failed step to succeed is not an option. Defeats the purpose of such a service. Should we move to another CI provider?
Thanks,
Ruben

2 Likes

No, it really is :slight_smile:

You can do it in steps:

  • Run your thing that might fail in step 1, and force a Unix success, but record how it went in a file
  • In the next step, do your clean-up
  • In your last step, force a failure if the file says the first step failed
1 Like

I have 15 steps in the pipeline. I’m not going to pollute all those 15 steps. Also, such procedure would also hide the real failed step in the UI, right?

I guess there is no other option than moving to another CI vendor.

Thanks

2 Likes

You can be cynical and defeatist, but remember, that’s a choice. If you keep on doing that, you will run out of vendors to loudly boycott - there are not very many good ones. (I’m just a fellow customer, and this forum’s annoying pro bono philosopher :grin:).

I think it would be a small tweak to two or three steps - it is hardly pollution.

It would, yes. I have seen a lot of CI pipelines, and I don’t think I have ever seen one where it mattered which step failed.

If you can give more detail - maybe with a friendly smile :joy_cat: - perhaps myself or other readers can give you more ideas.

1 Like

Well, running out of vendors is a real problem :slight_smile:

If not clearly seeing which step fails is not important, then you should also question the need of seeing step logs in the first place.

I’m running pretty complex pipeline, with unit tests, build, packaging, image upload, pretty complicated orchestration. Also involves acquiring custom AWS resources. But in reality this shouldn’t matter, cause in the end of the day I’m running just bunch of bash scripts (already reached to 20).

I’m using the pipeline both for production but also for active development. It is critical to clearly see which step fails and see the log output as quickly as possible. All i needed i just to run a step which executes in the end regardless of the pipeline status. Any more details I can provide that would help?

Is this smile good? :slight_smile:
tenor

1 Like

Urgh, no - that’s horrible. Real smiles please :slight_smile:

Unfortunately, neither of the smiles help with CI/CD

Do you need to do this “cleanup” for all of your steps? I agree, in that case, that it will bloat each step. Nevertheless, my attitude to CI is: get it working, get it fast, get it elegant. You’re on step 0 at the moment, so bloat it up if you have to.

(Would you remove that image from your post? Let’s practice kindness here if we can.)

Its a single cleanup for all steps. We are past 0. There are already two pipelines running (1 for dev, 1 for production).

What’s wrong with the picture? Its funny. Do you think it offends anyone?

1 Like

No idea if this was available when the question was asked last year, but for anyone looking for such functionality today, it is possible through the when property that can be added to any step. Circle’s default value is on_success. Other possible values are: on_fail and always.

Example
A step can be added at the end to always clean up external resources:

- run:
    name: Release licenses and shut down servers
    when: always
    command: cleanup.sh

More information on Circle’s docs: https://circleci.com/docs/2.0/configuration-reference/#the-when-attribute

5 Likes

if you are using 2.1. you can add a fan-in job and make the clean-up step always run:
e.g.
`

destroy-constructs:

docker:
  - image: your-image
steps:
  - checkout
  - run: 
      command: your-clean-up-command
      when: always

`

I tried to find a way too, and i found an orb swissknife that has function ( queue_jobs_within_workflow) to run a job after success/failure. I think this is the best workaround I found.
The only problem is that waiting only for one job. But you can take the code and change it to get a list of jobs instead of one.
Hopes it will help someone.

1 Like