Github Actions if condition requires "always()" to run but that makes it not cancellable #25789
-
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:
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
use |
Beta Was this translation helpful? Give feedback.
-
Tried that but behaves like the case I said of removing the always() the job is skipped 😦 |
Beta Was this translation helpful? Give feedback.
-
You want, success is false if any job where skipped
My own cheatsheet for job if’s
Job-level "if" condition not evaluated correctly if job in "needs" property is skipped
**Describe the bug** If a job `needs` a prior job which has been skipped, the `…if` condition for the dependent job may behave unexpectedly under some conditions. (unsure if condition is evaluated incorrectly or if it's not evaluated at all) To Reproduce on: push
jobs:
job_a:
runs-on: ubuntu-latest
outputs:
truthy_string: ${{ steps.a.outputs.always }}
null_value: ${{ steps.b.outputs.never }}
steps:
- id: a
run: echo "::set-output name=always::something"
- id: b
run: echo "We opt not to set any output at this time"
job_b:
runs-on: ubuntu-latest
needs: job_a
if: needs.job_a.outputs.null_value
steps:
- run: echo "We've ensured this job will be skipped"
job_c:
runs-on: ubuntu-latest
needs: [job_a, job_b]
if: needs.job_a.outputs.truthy_string
steps:
- run: echo "This won't run, even though the IF condition evaluates true."
job_d:
runs-on: ubuntu-latest
needs: [job_a, job_b]
if: always() && needs.job_a.outputs.truthy_string
steps:
- run: echo "This will run, even though we've only changed the condition from `true` to `true && true`" Examining the output of this workflow, job_a will always run, job_b will always be skipped, job_c will always be skipped, and job_d will run. Expected behavior OR documentation should be updated to indicate this is expected behavior. The current docks simply says of job Runner Version and PlatformVersion of your runner? OS of the machine running the runner? OSX/Windows/Linux/... What's not working?Jobs are being skipped even when the job-level conditional evaluates to Job Log OutputBecause the job is skipped entirely, there is no job-level output, even if the appropriate DEBUG secret is set. Runner and Worker's Diagnostic LogsAs above, there is no additional output, even if the appropriate DEBUG secret is set. |
Beta Was this translation helpful? Give feedback.
-
That worked like a charm @ChristopherHX thanks a lot for the cheatsheet |
Beta Was this translation helpful? Give feedback.
-
facing similar issue even without using needs. I have only one job which is doing nothing but just waiting still unable to cancel the run.
@ChristopherHX any suggestion ? |
Beta Was this translation helpful? Give feedback.
@mauriciodou
You want, success is false if any job where skipped
My own cheatsheet for job if’s
Job-level "if" condition not evaluated correctly if job in "needs" property is skipped