Run a post-entrypoint script on build cancellation

Hello everyone ! I am working on a Docker based Action and I am wondering if there is a way to run a post-entrypoint cleanup script whenever a build is cancelled by a user.

More specifically, will post-entrypoint run even if a build is cancelled, and is there a way to know in the runners contexts that a build is getting canceled so I could use this condition with post-if ?

Thanks in advance !

Yes, post-entrypoint will always run in default even if a build is cancelled.
post action
The post: action will only run if the conditions in post-if are met. If post-if is not set, then the condition defaults to always() .
You could use cancelled() function in post-if, then the post action will only run when the build is canceled.
if canceled

1 Like

Thanks a lot @yanjingzhu for your answer !

Hi @yanjingzhu, I tried to use the cancelled() function with post-if (in my action.yml) but after testing, I realize that it doesn’t work:

Here an excerpt of my action.yml file :slight_smile:

runs:
  using: 'docker'
  image: 'Dockerfile'
  entrypoint: '/app/entrypoint.sh'
  post-entrypoint: '/app/dokku-unlock.sh'
  post-if: ${{ cancelled() }}

Am i missing something ?
Thanks a lot in advance !

UPDATE : Never mind, using post-if: cancelled() (without ${{ }}) fix the issue