task icon indicating copy to clipboard operation
task copied to clipboard

ignore_error is not working with task and preconditions

Open ccxuy opened this issue 1 year ago • 1 comments

  • 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

ccxuy avatar Sep 25 '24 03:09 ccxuy

similar issue on #855

ccxuy avatar Sep 25 '24 03:09 ccxuy

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

trulede avatar Nov 12 '24 20:11 trulede

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

ccxuy avatar Nov 14 '24 03:11 ccxuy

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.

trulede avatar Dec 06 '25 19:12 trulede