Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defer no longer supporting passing vars (not interpolation) #1909

Open
toby-griffiths opened this issue Nov 6, 2024 · 0 comments
Open

Defer no longer supporting passing vars (not interpolation) #1909

toby-griffiths opened this issue Nov 6, 2024 · 0 comments
Labels
state: needs triage Waiting to be triaged by a maintainer.

Comments

@toby-griffiths
Copy link

We are using for loops to deploy things for a list of tenants, but for some reason the deferred command is missing any vars interpolated into the vars of the deferred task.

Example…

version: '3'

tasks:
  loop:
    vars:
      NAMES: 'Ana Bob Charlie'
    cmds:
      - for: { var: NAMES }
        task: 'test'
        vars:
          NAME: '{{ .ITEM }}'

  test:
    requires:
      vars: [ 'NAME' ]
    cmds:
      - task: 'x'
        vars:
          NAME: 'During: {{.NAME}}'
      - defer:
          task: 'x'
          vars:
            NAME: 'Deferred: {{.NAME}}'

  x:
    vars:
      requires: ['NAME']
    cmd: 'echo "{{.NAME}}"'

Results in …

task: [x] echo "During: Ana"
During: Ana
task: [x] echo "Deferred: "
Deferred:
task: [x] echo "During: Bob"
During: Bob
task: [x] echo "Deferred: "
Deferred:
task: [x] echo "During: Charlie"
During: Charlie
task: [x] echo "Deferred: "
Deferred:

You'll see from this example that the regular commands display the names, but the deferred ones do not.

If you interpolate into a direct command, rather than a task this works fine…

tasks:
  loop:
    vars:
      NAMES: 'Ana Bob Charlie'
    cmds:
      - for: { var: NAMES }
        task: 'test'
        vars:
          NAME: '{{ .ITEM }}'

  test:
    requires:
      vars: [ 'NAME' ]
    cmds:
      - task: 'x'
        vars:
          NAME: 'During: {{.NAME}}'
      - defer: 'echo "Deferred: {{.NAME}}"'

  x:
    vars:
      requires: ['NAME']
    cmd: 'echo "{{.NAME}}"'

Resulting in…

$ task loop
task: [x] echo "During: Ana"
During: Ana
task: [test] echo "Deferred: Ana"
Deferred: Ana
task: [x] echo "During: Bob"
During: Bob
task: [test] echo "Deferred: Bob"
Deferred: Bob
task: [x] echo "During: Charlie"
During: Charlie
task: [test] echo "Deferred: Charlie"
Deferred: Charlie
  • Task version: v3.39.2 (h1:Zt7KXHmMNq5xWZ1ihphDb+n2zYLCo4BdRe09AnMMIgA=)
  • Operating system: MacOS 14.6.1 (23G93)
  • Experiments enabled: None
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: needs triage Waiting to be triaged by a maintainer.
Projects
None yet
Development

No branches or pull requests

2 participants