Skip to content

provide private variables for all tasks in a given taskfile #306

Closed as duplicate

Description

@qbalsoftware

A/Taskefile.yml
vars:
FOO = abc

B/Taskfile.yml
vars:
FOO = zyz

Taskfile.yml
includes:
A : A/Taskfile.yml
B: B/Taskfile.yml

calling a task in A will always use the value of B > FOO

Global (already have this). FOO = abc
per Taskfile (do not have this) FOO = xyz
per task per Taskfile (already have this) FOO = yada yada yada

Activity

  1. andreynering commented on Mar 22, 2020

    @andreynering
    Member

    Hi @138over,

    It's possible that this will be fixed in v3 though #218.

    For now, I'd say this is just not supported and I advice using different variable names.

  2. tobiashochguertel commented on Aug 27, 2025

    @tobiashochguertel

    This is not yet implemented or?

    I'm using a variable NAMESPACE in all my Taskfiles to define the namespace of the Taskfile; that is useful when I want to call a task from the same Taskfile.

    version: '3'
    
    shopt: [globstar, expand_aliases]
    
    includes:
      auth: ./auth.yml
      common: ./common.yml
      ports: ./ports.yml
    
    vars:
      # Namespace for this taskfile
      NAMESPACE: '{{.NAMESPACE | default "registry"}}'
    
      # Special variables
      T: '{{.TASK_EXE}}'
      WORKING_DIR: '{{.USER_WORKING_DIR}}'
    
    tasks:
      detect:
        desc: Detect the operating system
        dir: '{{.WORKING_DIR}}'
        cmds:
          - |
            # Debug output to stderr (won't affect the return value)
            if [ "{{.DEBUG}}" = "true" ]; then
              echo "DEBUG: Running detect-os, uname=$(uname)" >&2
            fi
    
            if [ "$(uname)" = "Darwin" ]; then
              echo "macos"
            elif [ "$(uname)" = "Linux" ]; then
              echo "linux"
            else
              echo "unsupported"
            fi
    
      check-config:
        desc: Check Docker daemon configuration for registry compatibility
        dir: '{{.WORKING_DIR}}'
        vars:
          TASK_SILENT: "{{if .CLI_SILENT}}--silent{{end}}"
          TASK_ARGS: "{{.TASK_SILENT | catLines}}"
          T: '{{.TASK_EXE}} {{.TASK_ARGS}}'
        cmds:
          - |-
            # Source error handling functions
            {{.FUNCS.debug}}
            {{.FUNCS.error}}
            {{.FUNCS.warn}}
            {{.FUNCS.info}}
            {{.FUNCS.success}}
            {{.FUNCS.check_command}}
    
            # Capture OS detection output with logging
            OS_CMD="{{.T}} {{.NAMESPACE}}:detect"
    

    But that doesn't work correctly when with every include of a Taskfile the variable like NAMESPACE gets a new value. Because a Taskfile shares with all its included Taskfiles the variables, no Taskfile has its own variable space.

  3. trulede commented on Feb 8, 2026

    @trulede
    Contributor

    There is a PR where you can offer feedback #2659

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fields

    No fields configured for feature.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions