Skip to content

"Required Variables" and results of cmd #169

Closed
Closed

Description

@stephenprater

Is there way to set "preconditions" on a task? I have some tasks that require a certain variable to be set. Currently I'm just dropping a test -n in the cmd array and letting it die if it's not set, and setting the default value of the variable to "" - but that seems like kind of a round about way of achieving this.

The other "issue" I'm having is whether or not it's possible to pass the results of one command to the next command (as a variable or otherwise) without having to write a temporary file. Again, I can work around this by calling tasks from other tasks and having the "result" that I want be re-computed by a dynamic variable in the sub task, but that implicates the "precondition" feature I mentioned earlier.

The actual use case is that I want to kick off a creating an AMI if the AMI does not already exist, and then pass the output of the "import-task" into a different AWS API call once it's finished. Again, I can accomplish this using multiple tasks, but it makes my tasks very tightly coupled to each other (like "register-image" can only be run by being called from "import-snapshot"

Activity

  1. andreynering commented on Jan 26, 2019

    @andreynering
    Member

    Hi @stephenprater,

    Is there way to set "preconditions" on a task? I have some tasks that require a certain variable to be set. Currently I'm just dropping a test -n in the cmd array and letting it die if it's not set, and setting the default value of the variable to "" - but that seems like kind of a round about way of achieving this.

    Task doesn't have this feature (at least yet). What is possible to do, though, is having a default value for a task:

    version: '2'
    
    tasks:
      echo:
        cmds:
          - echo "{{.MSG | default "empty"}}"

    The other "issue" I'm having is whether or not it's possible to pass the results of one command to the next command (as a variable or otherwise) without having to write a temporary file.

    I think this was asked before, but no, Task also doesn't have this feature yet.

    Again, I can work around this by calling tasks from other tasks and having the "result" that I want be re-computed by a dynamic variable in the sub task, but that implicates the "precondition" feature I mentioned earlier.

    Hmm... so your problem here seems to be that variables are cached? They indeed are, i.e., if you populate a variable from a syntax like {sh: '...'} it'll run only once and be cached for future uses.

    You could in theory cheat Task to re-run it by using templating to change anything on the command, then it'll re-run. Since this isn't reasonable from a UX perspective, we could add a flag or option to disable this.

  2. andreynering commented on Mar 23, 2019

    @andreynering
    Member

    Hi @stephenprater

    It's now 3 months since you opened this issue. Do you have more thoughts? Have you find a way to solve your problem?

    The problem with this issue is that there isn't a single actionable thing here. If you'd like to propose features requests, I'd advice to open separate issues for each one.

    What do you think?

  3. stephenprater commented on Mar 23, 2019

    @stephenprater
    ContributorAuthor

    @andreynering I would like to propose these as feature requests. I've started working on them actually and I'm aiming to have PRs sometime soon.

    I'll go ahead and close this one since it's more like a "support request" and you answered my questions!

    Thanks!

  4. stephenprater commented on May 17, 2019

    @stephenprater
    ContributorAuthor

    #205 Adds the precondition feature I mention here.

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

    No labels
    No labels

    Fields

    No fields configured for support.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions