Skip to content

[Bug:] Custom task directory (set with dir) is not created before initializing dynamic variable #1841

@ColorfulRhino

Description

@ColorfulRhino

Consider the following task using a custom dir:

version: '3'

tasks:
  test:
    dir: test-dir
    vars:
      TEST_VAR: "This is a test"
    cmds:
      - echo "This is a test. Using TEST_VAR with value: ${TEST_VAR}"

The above task will create the directory test-dir before executing the command if it is not already created.

However, when using a dynamic variable instead, like this:

version: '3'

tasks:
  test:
    dir: test-dir
    vars:
      TEST_VAR:
        sh: curl https://taskfile.dev
    cmds:
      - echo "This is a test. Using TEST_VAR with value: ${TEST_VAR}"

It fails to execute when the directory test-dir does not yet exist:
task: Command "curl https://taskfile.dev" failed: chdir /home/user/test-dir: no such file or directory

Expected behaviour:
The directory should be created before trying to execute the dynamic variable initialization command.


  • Task version: v3.39.2
  • Operating system: Ubuntu 24.04
  • Experiments enabled: no

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions