Job-level "if" condition not evaluated correctly if job in "needs" property is skipped
Problem
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 Steps to reproduce the behavior: Given a workflow such as this (where job_b needs to complete or be skipped before subsequent jobs run, but subsequent jobs don't depend upon any outputs from job_b) [code block] 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. The only difference between job_c and job_d is the addition of `always() &&` to the `if` condition. Expected behavior If a job-level conditional evaluates to `true`, the job should run after all `needs`'d jobs have completed or been skipped. _Both_ job_c and job_d should run. The `always() &&` should not be required for job_c, since it doesn't change the ultimate true/false result of the conditional. OR documentation should be updated to indicate this is expected behavior. The current docks simply says of job `needs` (emphasis added): > Identifies any jobs that must complete successfully before this job will run. It can be a string or array of strings. If a job fails, all jobs that need it are skipped unless the jobs use a conditional statement that causes the job to continue. This is relatively ambiguous, but the plain interpretation is that a conditional statement that evaluates
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Fix Job-Level Conditional Evaluation for Skipped Jobs
The issue arises because job-level conditionals are not evaluated correctly when a job in the 'needs' property is skipped. This leads to dependent jobs not running as expected, even if their condition evaluates to true. The current behavior is ambiguous and does not align with user expectations regarding job execution based on conditionals.
Awaiting Verification
Be the first to verify this fix
- 1
Update Job Definitions
Modify the job definitions to ensure that the conditional logic is properly applied. Specifically, add a check for the skipped state of the jobs in the 'needs' property.
yamljob_c: if: needs.job_b == 'success' || needs.job_b == 'skipped' runs: ... - 2
Implement Conditional Logic
Ensure that all jobs that depend on skipped jobs include a conditional statement that checks for both success and skipped states. This will ensure they run as expected.
yamljob_d: if: always() || needs.job_b == 'skipped' runs: ... - 3
Test Workflow Execution
Run the modified workflow to verify that both job_c and job_d execute correctly when job_b is skipped. Ensure that the outputs are as expected and that the conditionals are evaluated properly.
yamlworkflow: on: [push] jobs: job_a: runs: ... job_b: runs: ... job_c: runs: ... job_d: runs: ... - 4
Update Documentation
Revise the documentation to clarify the expected behavior of job-level conditionals in relation to skipped jobs. Ensure that users understand how to implement the necessary checks for their workflows.
markdownDocumentation Update: - Clarify that conditionals should check for both success and skipped states. - Provide examples of correct usage.
Validation
Confirm the fix by executing the workflow with job_b skipped. Both job_c and job_d should run successfully. Review the logs to ensure that the conditionals were evaluated as intended without requiring 'always()' for job_c.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep