task icon indicating copy to clipboard operation
task copied to clipboard

Required vars not required when calling tasks

Open mvhatch opened this issue 11 months ago • 1 comments

I tried looking to see if this was already an issue but did not find anything. Also, wasn't sure if this is a bug or a feature request.

  helm-diff:
    desc: Show the diff between the current and previous helm release
    cmds:
      - task: common:helm-diff
        vars:
          HELM_ARGS: "-f=./helm/{{.PROJ}}.yaml --set image.tag={{.DOCKER_IMAGE_TAG}}"
          K8S_REGION: '{{dig .PROJ "region" .DEFAULT_K8S_REGION (mustFromJson .K8S_CONFIG)}}'
          K8S_CLUSTER: '{{dig .PROJ "cluster" .DEFAULT_K8S_CLUSTER (mustFromJson .K8S_CONFIG)}}'
    requires:
      vars: [PROJ]

Expected running task helm-diff fails with: task: Task "helm-diff" cancelled because it is missing required variables: PROJ

Actual task runs successfully. Note: PROJ has no default value. For comparison, this works as expected.

  helm-diff:
    desc: Show the diff between the current and previous helm release
    cmds:
      - cmd: echo "helm diff"
        vars:
          HELM_ARGS: "-f=./helm/{{.PROJ}}.yaml --set image.tag={{.DOCKER_IMAGE_TAG}}"
          K8S_REGION: '{{dig .PROJ "region" .DEFAULT_K8S_REGION (mustFromJson .K8S_CONFIG)}}'
          K8S_CLUSTER: '{{dig .PROJ "cluster" .DEFAULT_K8S_CLUSTER (mustFromJson .K8S_CONFIG)}}'
    requires:
      vars: [PROJ]
  • Task version: v3.35.1
  • Operating system: MacOS arm64
  • Experiments enabled: none

mvhatch avatar Mar 20 '24 18:03 mvhatch

Tried this:

version: '3'
tasks:
  foo:
    vars:
      BAR: '{{.BAR | default "who"}}'  # also works without this line
    cmds:
      - echo {{.BAR}}
  bar:
    cmds:
      - task: foo
        vars:
          BAR: "{{.PROJ}}"
    requires:
      vars: [PROJ]

which yields:

$ task foo
task: [foo] echo who
who
$ task bar
task: Task "bar" cancelled because it is missing required variables: PROJ
$ task bar PROJ=fubar
task: [foo] echo fubar
fubar

Can you provide a more complete example that causes the problem? Is it possible that ".PROJ" was defined somewhere in "common:helm-diff" and so was actually considered not missing?

trulede avatar Mar 31 '24 20:03 trulede

Happened to me as well, here is a minimal example:

  docker-build:
    cmds:
      - echo "Building {{.IMAGE_NAME}}"
    requires:
      vars: [IMAGE_NAME]

Now running: task docker-build

Should fail, but instead prints: Building

neriaad avatar Oct 22 '24 12:10 neriaad

@neriaad Your example is working as expected cf : image

@mvhatch Can you provide the full example (that I can copy / past) ?

vmaerten avatar Oct 22 '24 18:10 vmaerten