CircleCI-Public / config-preview-sdk

Preview SDK for orb authors
85 stars 29 forks source link

Support for array/list/set parameter and foreach #45

Open matfax opened 6 years ago

matfax commented 6 years ago

I would like to make another suggestion for a further feature. For me, it would come very handy if you added support for some kind of array, list or set parameter that can be parsed to a list of steps. Here is an example of how it may look:

commands:
  send:
    parameters:
      messages:
        description: "Messages to use"
        type: list #sorted
        items: # like Swagger
          type: string
        default: ["hey", "ho"]
    steps:
    - run: wait for connection
    - foreach:
        elements: << parameters.messages >>
        steps:
          - run: prepare next message
          - run: send << foreach.messages >> # use a different prefix group allowing nested foreachs without conflicts
    - foreach:
        elements: << parameters.messages >>
        id: msg
        steps:
          - run: prepare saving
          - run: save << foreach.msg >>

This is just an example, but imagine the same for build preparation where you pass a variable number of arguments per build, having a 1:n relation. I could use that for docker tag << foreach.tag >>.

dnephin commented 6 years ago

It seems to me like a string type would be more appropriate for your example. The values are being used as part of a shell command, which is a string. Using a list introduces new problems, like how should the list be joined to create a string (which is what is actually needed). We could assume it will always be joined with a single space, but that may not always be a safe assumption.

Edit: reading the last line I see that the desired behaviour is not what I first expected. It is to expand a single step into multiple steps.

matfax commented 6 years ago

@dnephin You are right, foreach would be more appropriate.

ndintenfass commented 6 years ago

This is something we're exploring, but we're hesitant to put too much control flow logic at the meta-layer. We aren't trying to build a programming language in YAML, but we do want to find ways to let you do common things in a DRY way.

bunchc commented 5 years ago

Hello, Is there a way or practice or method by which this can achieved in the current product? Thanks!

davidbarkhuizen commented 1 year ago

+100. Please implement as soon as possible.

doron2402 commented 1 year ago

Any update on that?

eytan-sankin commented 1 year ago

Would come in handy indeed.

matfax commented 11 months ago

I'm quite disappointed that this is still unresolved, after five years.