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

Allow interpolation in task names when calling another task? #410

Closed
sergeyberezansky opened this issue Nov 26, 2020 · 4 comments
Closed
Labels
good first issue Issues that are good for first-time contributors to pick up. help wanted Issues that could benefit from members of the community contributing their expertise or experience.

Comments

@sergeyberezansky
Copy link

sergeyberezansky commented Nov 26, 2020

Hello, I am struggling to resolve task name based on variable

Having 2 different modes of task execution, and would like to support them both without making commands complicated
For this reason, tried to either separate the tasks into different include files,
or just create another tasks and then try to call them by name with variable expansion
Nothing works

Want, for example, to support local environment to work both with docker and minikube, and bring up the desired env according to env param.

# env installation_mode=docker

tasks: 
  install_database :
    cmds:
       - task: install_database_{{.installation_mode}}

  install_database_docker:
    - cmds:
      - docker run ...

  install_database_kube:
    - cmds:
     - kubectl apply...

Is this supported? What I am missing here?

@mknapik
Copy link

mknapik commented Dec 16, 2020

{{.installation_mode}} interpolates Taskfile variable which is not the same as shell env var.

The following config would use env vars:

tasks:
  install_database_env_var:
    cmds:
       - echo "env_var install_database_${INSTALLATION_MODE}"
       - task: "install_database_${INSTALLATION_MODE}"
    preconditions:
      - test -n "${INSTALLATION_MODE}"

  install_database_docker:
    cmds:
      - echo "install_database_docker"

  install_database_kube:
    cmds:
     - echo "install_database_kube"

However, it doesn't work for me so I guess it's not supported.

You can work around the problem by using shell instead of task command:

tasks:
  install_database_env_var:
    cmds:
       - echo "env_var install_database_${INSTALLATION_MODE}"
       - task install_database_${INSTALLATION_MODE}
    preconditions:
      - test -n "${INSTALLATION_MODE}"

  install_database_docker:
    cmds:
      - echo "install_database_docker"

  install_database_kube:
    cmds:
     - echo "install_database_kube"
$ env INSTALLATION_MODE=docker task install_database_env_var
task: echo "install_database_${INSTALLATION_MODE}"
install_database_docker
task: task install_database_${INSTALLATION_MODE}
task: echo "install_database_docker"
install_database_docker

@andreynering andreynering changed the title variables are not expanded in task names Allow interpolation in task names when calling another task? Feb 20, 2021
@andreynering andreynering added type: feature A new feature or functionality. good first issue Issues that are good for first-time contributors to pick up. help wanted Issues that could benefit from members of the community contributing their expertise or experience. labels Feb 20, 2021
@andreynering
Copy link
Member

Hi @sergeyberezansky, thanks for opening this issue!

Yep, that's indeed not supported, but I'll keep this issue opened so we may implement it.

@vmaerten
Copy link
Member

AFAIK, it's supported now

@andreynering can you confirm and maybe close this one ?

@pd93
Copy link
Member

pd93 commented May 11, 2024

This is definitely supported in the latest versions

@pd93 pd93 closed this as completed May 11, 2024
@pd93 pd93 removed the type: feature A new feature or functionality. label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Issues that are good for first-time contributors to pick up. help wanted Issues that could benefit from members of the community contributing their expertise or experience.
Projects
None yet
Development

No branches or pull requests

5 participants