ignore_error is not working with task and preconditions
- Task version: Task version: v3.38.0 (h1:O7kgA6BfwktXHPrheByQO46p3teKtRuq1EpGnFxNzbo=)
- Operating system: Ubuntu 2204
- Experiments enabled: No
empty:
vars:
a:
sh: echo 1
cmds:
- echo {{.a}}
- task: none
ignore_error: true
vars:
a: 1
- echo {{.a}}
none:
preconditions:
- sh: '[ "{{.a}}" = "2" ]'
cmds:
- exit 1
> task empty
task: [empty] echo 1
1
task: [ "1" = "2" ] failed
task: Failed to run task "empty": task: precondition not met
Failed at 192: task empty
similar issue on #855
Delete the precondition. Its senseless (IMMHO) to have a task with a precondition, call it, and then have an option to bypass the precondition.
However, what you could is add a task in-between to manage the situation, something like this:
run_foo:
vars:
a:
sh: echo 1
cmds:
- echo {{.a}}
- task: foo
ignore_error: true
vars:
a: 1
- echo {{.a}}
- task: foo_with_precondition
ignore_error: true
vars:
a: 2
foo_with_precondition:
preconditions:
- sh: '[ "{{.a}}" = "2" ]'
cmds:
- task: foo
foo:
cmds:
- exit 1
Precondition is really difficult to use, what Task actually needs is branching, I really need if statments to make task go to different sub-task
The ignore_error applies specifically to the task call, and is a duplicate of #855.
status will work better than preconditions for what you are attempting to do. Its logically the inverse of if but you can still do something with that.
An if like item would be a duplicate of #608.