Github Actions if condition requires "always()" to run but that makes it not cancellable

Hi Community.

I am having this weird situation where my job’s if condition requires to have the “always()” function in order to run. If I use another function like “success()” or even putting “true” hardcoded doesn’t work. The problem with using “always()” is that now the job cannot be cancelled.

Here’s the job if piece:

  WorkspaceVariables:
    needs: [build-matrix]
    env:
      terraservice_name: "00-workspace-variables"
    if: |
      always() &&
      needs.build-matrix.result == 'success' &&
      needs.build-matrix.outputs.matrix != null &&
      contains(fromJson(needs.build-matrix.outputs.all-matrix).terraservice, 'environments/dev-centralus/00-workspace-variables') &&
      contains(fromJson(needs.build-matrix.outputs.matrix).terraservice, 'environments/dev-centralus/00-workspace-variables')

use success() || failure() , it should make the job always run but also not run if you cancel.

Tried that but behaves like the case I said of removing the always() the job is skipped :frowning:

@mauriciodou

You want, success is false if any job where skipped

if: "!cancelled()"

My own cheatsheet for job if’s

1 Like

That worked like a charm @ChristopherHX thanks a lot for the cheatsheet