CircleCI-Public/config-preview-sdk

Support for array/list/set parameter and foreach

matfax opened this issue ยท 8 comments

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 >>.

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.

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

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.

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

+100. Please implement as soon as possible.

Any update on that?

Would come in handy indeed.

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