Task: Clear variables cache between runs when watching?

Created on 22 Aug 2020  路  3Comments  路  Source: go-task/task

If I run a task that watches foo.txt for changes, I would like to dynamically set a var on every execution/change to foo.txt, however I cannot get it to work with this example configuration; DYN_VAR always remains set the first value of date.

OS: macos 10.15.5

$ task --version
Task version: 3.0.0
version: '3'

tasks:
  foobar:
    sources:
      - ./foo.txt
    generates:
      - ./bar.txt
    vars:
      DYN_VAR:
        sh: date
    cmds:
      - echo "{{.DYN_VAR}}" > ./bar.txt
$ task foobar -w
task: Started watching for tasks: foobar
task: echo "Sat Aug 22 23:25:20 NZST 2020" > ./bar.txt
task: Task "foobar" is up to date
# changes manually made to foo.txt
task: echo "Sat Aug 22 23:25:20 NZST 2020" > ./bar.txt
task: Task "foobar" is up to date

Is it possible to do what I am trying, if so how?

bug watch

All 3 comments

Hi @craighurley,

That happens because variables are cached in the first run.

We should probably re-evaluate that on every run.

Try this.

version: '3'

tasks:
  foobar:
    sources:
      - ./foo.txt
    generates:
      - ./bar.txt
    cmds:
      - |
        DYN_VAR=$(date)
        echo "$DYN_VAR" > ./bar.txt

Thanks @dschissler, that works.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

marco-m picture marco-m  路  5Comments

fj picture fj  路  4Comments

antonmarin picture antonmarin  路  8Comments

shrink picture shrink  路  4Comments

moritzheiber picture moritzheiber  路  3Comments